|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Bavix\Glow\Test; |
| 4 | + |
| 5 | +use Bavix\Glow\Adapters\Cover; |
| 6 | + |
| 7 | +class GDCoverTest extends TestCase |
| 8 | +{ |
| 9 | + |
| 10 | + /** |
| 11 | + * @var string |
| 12 | + */ |
| 13 | + protected $driver = 'gd'; |
| 14 | + |
| 15 | + /** |
| 16 | + * @dataProvider sizes |
| 17 | + * @param string $path |
| 18 | + * @param array $data |
| 19 | + * @param array $units |
| 20 | + * @return void |
| 21 | + */ |
| 22 | + public function testSizeResultImage(string $path, array $data, array $units): void |
| 23 | + { |
| 24 | + $adapter = new Cover($this->imageManager); |
| 25 | + $image = $this->imageManager->make($path); |
| 26 | + $processed = $adapter->apply($image, $data); |
| 27 | + |
| 28 | + self::assertEquals($units['width'], $processed->width()); |
| 29 | + self::assertEquals($units['height'], $processed->height()); |
| 30 | + $processed->destroy(); |
| 31 | + $image->destroy(); |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * @return array[] |
| 36 | + */ |
| 37 | + public function sizes(): array |
| 38 | + { |
| 39 | + return [ |
| 40 | + [ |
| 41 | + __DIR__ . '/images/width.jpg', |
| 42 | + [ |
| 43 | + 'width' => 500, |
| 44 | + 'height' => 500, |
| 45 | + ], |
| 46 | + ['width' => 500, 'height' => 500], |
| 47 | + ], |
| 48 | + [ |
| 49 | + __DIR__ . '/images/width.jpg', |
| 50 | + [ |
| 51 | + 'width' => 800, |
| 52 | + 'height' => 800, |
| 53 | + ], |
| 54 | + ['width' => 800, 'height' => 800], |
| 55 | + ], |
| 56 | + [ |
| 57 | + __DIR__ . '/images/width.jpg', |
| 58 | + [ |
| 59 | + 'width' => 780, |
| 60 | + 'height' => 462, |
| 61 | + ], |
| 62 | + ['width' => 780, 'height' => 462], |
| 63 | + ], |
| 64 | + [ |
| 65 | + __DIR__ . '/images/height.jpg', |
| 66 | + [ |
| 67 | + 'width' => 500, |
| 68 | + 'height' => 500, |
| 69 | + ], |
| 70 | + ['width' => 500, 'height' => 500], |
| 71 | + ], |
| 72 | + [ |
| 73 | + __DIR__ . '/images/height.jpg', |
| 74 | + [ |
| 75 | + 'width' => 800, |
| 76 | + 'height' => 800, |
| 77 | + ], |
| 78 | + ['width' => 800, 'height' => 800], |
| 79 | + ], |
| 80 | + [ |
| 81 | + __DIR__ . '/images/height.jpg', |
| 82 | + [ |
| 83 | + 'width' => 780, |
| 84 | + 'height' => 462, |
| 85 | + ], |
| 86 | + ['width' => 780, 'height' => 462], |
| 87 | + ], |
| 88 | + [ |
| 89 | + __DIR__ . '/images/square.jpg', |
| 90 | + [ |
| 91 | + 'width' => 500, |
| 92 | + 'height' => 500, |
| 93 | + ], |
| 94 | + ['width' => 500, 'height' => 500], |
| 95 | + ], |
| 96 | + [ |
| 97 | + __DIR__ . '/images/square.jpg', |
| 98 | + [ |
| 99 | + 'width' => 800, |
| 100 | + 'height' => 800, |
| 101 | + ], |
| 102 | + ['width' => 800, 'height' => 800], |
| 103 | + ], |
| 104 | + [ |
| 105 | + __DIR__ . '/images/square.jpg', |
| 106 | + [ |
| 107 | + 'width' => 780, |
| 108 | + 'height' => 462, |
| 109 | + ], |
| 110 | + ['width' => 780, 'height' => 462], |
| 111 | + ], |
| 112 | + ]; |
| 113 | + } |
| 114 | + |
| 115 | +} |
0 commit comments