|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Orbitale\Component\ImageMagick\Tests; |
| 6 | + |
| 7 | +use Orbitale\Component\ImageMagick\Command; |
| 8 | +use Orbitale\Component\ImageMagick\ReferenceClasses\Gravity; |
| 9 | + |
| 10 | +class GravityTest extends AbstractTestCase |
| 11 | +{ |
| 12 | + /** |
| 13 | + * @param string $gravity |
| 14 | + * |
| 15 | + * @dataProvider provideValidGravities |
| 16 | + */ |
| 17 | + public function testGravity($gravity): void |
| 18 | + { |
| 19 | + $gravity = new Gravity($gravity); |
| 20 | + |
| 21 | + $validatedGravity = $gravity->validate(); |
| 22 | + |
| 23 | + static::assertNotEmpty($validatedGravity); |
| 24 | + |
| 25 | + $command = new Command(IMAGEMAGICK_DIR); |
| 26 | + |
| 27 | + $outputFile = $this->resourcesDir.'/outputs/moon_180_test_gravity_'.\md5($gravity.'test_geo').'.jpg'; |
| 28 | + |
| 29 | + if (\file_exists($outputFile)) { |
| 30 | + \unlink($outputFile); |
| 31 | + } |
| 32 | + |
| 33 | + $command |
| 34 | + ->convert($this->resourcesDir.'/moon_180.jpg') |
| 35 | + ->gravity($gravity) |
| 36 | + ->resize('100x100') |
| 37 | + ->file($outputFile, false) |
| 38 | + ; |
| 39 | + |
| 40 | + $response = $command->run(); |
| 41 | + |
| 42 | + static::assertTrue($response->isSuccessful(), \sprintf( |
| 43 | + "Gravity fixture \"%s\" returned an ImageMagick error.\nFull command: %s\nErrors:\n%s\n%s", |
| 44 | + $gravity->validate(), |
| 45 | + $command->getCommand(), |
| 46 | + $response->getOutput(), |
| 47 | + $response->getError() |
| 48 | + )); |
| 49 | + static::assertFileExists($outputFile); |
| 50 | + } |
| 51 | + |
| 52 | + public function provideValidGravities(): ?\Generator |
| 53 | + { |
| 54 | + yield 0 => ["NorthWest"]; |
| 55 | + yield 1 => ["North"]; |
| 56 | + yield 2 => ["NorthEast"]; |
| 57 | + yield 3 => ["West"]; |
| 58 | + yield 4 => ["Center"]; |
| 59 | + yield 5 => ["East"]; |
| 60 | + yield 6 => ["SouthWest"]; |
| 61 | + yield 7 => ["South"]; |
| 62 | + yield 8 => ["SouthEast"]; |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * @param string $gravity |
| 67 | + * |
| 68 | + * @dataProvider provideWrongGravities |
| 69 | + */ |
| 70 | + public function testWrongGravities($gravity): void |
| 71 | + { |
| 72 | + $this->expectException(\InvalidArgumentException::class); |
| 73 | + $this->expectExceptionMessage("Invalid gravity option, \"" .$gravity. "\" given.\nAvailable: NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast" ); |
| 74 | + |
| 75 | + $testGravity = new Gravity($gravity); |
| 76 | + $testGravity->validate(); |
| 77 | + } |
| 78 | + |
| 79 | + public function provideWrongGravities(): ?\Generator |
| 80 | + { |
| 81 | + yield 0 => ["Northwest"]; |
| 82 | + yield 1 => ["northwest"]; |
| 83 | + yield 2 => ["north"]; |
| 84 | + yield 3 => ["northEast"]; |
| 85 | + yield 4 => ["Northeast"]; |
| 86 | + yield 5 => ["west"]; |
| 87 | + yield 6 => ["center"]; |
| 88 | + yield 7 => ["east"]; |
| 89 | + yield 8 => ["southwest"]; |
| 90 | + yield 9 => ["south"]; |
| 91 | + yield 10 => ["southeast"]; |
| 92 | + yield 11 => ["Middle"]; |
| 93 | + yield 12 => [""]; |
| 94 | + yield 13 => [" "]; |
| 95 | + } |
| 96 | +} |
0 commit comments