123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- namespace fphammerle\helpers\tests;
- use fphammerle\helpers\Image;
- class ImageTest extends \PHPUnit_Framework_TestCase
- {
- public function rotateProvider()
- {
- return [
- [__DIR__ . '/data/chainring.jpg', 90, __DIR__ . '/data/chainring-rotated-left.jpg'],
- [__DIR__ . '/data/chainring.jpg', 270, __DIR__ . '/data/chainring-rotated-right.jpg'],
- ];
- }
- /**
- * @dataProvider rotateProvider
- */
- public function testRotate($source_path, $angle, $expected_path)
- {
- $img = Image::fromFile($source_path);
- $tmp_path = tempnam(sys_get_temp_dir(), 'image');
- $img->rotate($angle);
- $img->saveJpeg($tmp_path);
- $this->assertFileEquals($expected_path, $tmp_path);
- unlink($tmp_path);
- }
- public function rotateLeftProvider()
- {
- return [
- [__DIR__ . '/data/chainring.jpg', __DIR__ . '/data/chainring-rotated-left.jpg'],
- ];
- }
- /**
- * @dataProvider rotateLeftProvider
- */
- public function testRotateLeft($source_path, $expected_path)
- {
- $img = Image::fromFile($source_path);
- $tmp_path = tempnam(sys_get_temp_dir(), 'image');
- $img->rotateLeft();
- $img->saveJpeg($tmp_path);
- $this->assertFileEquals($expected_path, $tmp_path);
- unlink($tmp_path);
- }
- public function rotateRightProvider()
- {
- return [
- [__DIR__ . '/data/chainring.jpg', __DIR__ . '/data/chainring-rotated-right.jpg'],
- ];
- }
- /**
- * @dataProvider rotateRightProvider
- */
- public function testRotateRight($source_path, $expected_path)
- {
- $img = Image::fromFile($source_path);
- $tmp_path = tempnam(sys_get_temp_dir(), 'image');
- $img->rotateRight();
- $img->saveJpeg($tmp_path);
- $this->assertFileEquals($expected_path, $tmp_path);
- unlink($tmp_path);
- }
- public function testSaveJpeg()
- {
- $img = Image::fromFile(__DIR__ . '/data/chainring.jpg');
- $tmp_path = tempnam(sys_get_temp_dir(), 'image');
- $img->saveJpeg($tmp_path);
- $this->assertFileEquals(__DIR__ . '/data/chainring-saved.jpg', $tmp_path);
- unlink($tmp_path);
- }
- }
|