|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Copyright (c) Florian Krämer (https://florian-kraemer.net) |
| 5 | + * Licensed under The MIT License |
| 6 | + * For full copyright and license information, please see the LICENSE.txt |
| 7 | + * Redistributions of files must retain the above copyright notice. |
| 8 | + * |
| 9 | + * @copyright Copyright (c) Florian Krämer (https://florian-kraemer.net) |
| 10 | + * @author Florian Krämer |
| 11 | + * @link https://github.com/Phauthentic |
| 12 | + * @license https://opensource.org/licenses/MIT MIT License |
| 13 | + */ |
| 14 | + |
| 15 | +declare(strict_types=1); |
| 16 | + |
| 17 | +namespace Phauthentic\Test\TestCase\Processor\Image; |
| 18 | + |
| 19 | +use Intervention\Image\Image; |
| 20 | +use Phauthentic\Infrastructure\Storage\Processor\Image\Operations; |
| 21 | +use Phauthentic\Test\TestCase\TestCase; |
| 22 | + |
| 23 | +/** |
| 24 | + * OperationsTest |
| 25 | + */ |
| 26 | +class OperationsTest extends TestCase |
| 27 | +{ |
| 28 | + /** |
| 29 | + * @return void |
| 30 | + */ |
| 31 | + public function testOperations(): void |
| 32 | + { |
| 33 | + $imageMock = $this->getMockBuilder(Image::class) |
| 34 | + ->addMethods([ |
| 35 | + 'resize' |
| 36 | + ]) |
| 37 | + ->getMock(); |
| 38 | + |
| 39 | + $operations = new Operations($imageMock); |
| 40 | + |
| 41 | + $imageMock->expects($this->once()) |
| 42 | + ->method('resize') |
| 43 | + ->with(100, 100); |
| 44 | + |
| 45 | + $operations->resize(['height' => 100, 'width' => 100]); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * @return void |
| 50 | + */ |
| 51 | + public function testHeighten(): void |
| 52 | + { |
| 53 | + $imageMock = $this->getMockBuilder(Image::class) |
| 54 | + ->addMethods([ |
| 55 | + 'heighten' |
| 56 | + ]) |
| 57 | + ->getMock(); |
| 58 | + |
| 59 | + $operations = new Operations($imageMock); |
| 60 | + |
| 61 | + $imageMock->expects($this->once()) |
| 62 | + ->method('heighten') |
| 63 | + ->with(100); |
| 64 | + |
| 65 | + $operations->heighten(['height' => 100]); |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * @return void |
| 70 | + */ |
| 71 | + public function testWiden(): void |
| 72 | + { |
| 73 | + $imageMock = $this->getMockBuilder(Image::class) |
| 74 | + ->addMethods([ |
| 75 | + 'widen' |
| 76 | + ]) |
| 77 | + ->getMock(); |
| 78 | + |
| 79 | + $operations = new Operations($imageMock); |
| 80 | + |
| 81 | + $imageMock->expects($this->once()) |
| 82 | + ->method('widen') |
| 83 | + ->with(100); |
| 84 | + |
| 85 | + $operations->widen(['width' => 100]); |
| 86 | + |
| 87 | + $this->expectException(\InvalidArgumentException::class); |
| 88 | + $this->expectExceptionMessage('Missing width'); |
| 89 | + $operations->widen([]); |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * @return void |
| 94 | + */ |
| 95 | + public function testRotate(): void |
| 96 | + { |
| 97 | + $imageMock = $this->getMockBuilder(Image::class) |
| 98 | + ->addMethods([ |
| 99 | + 'rotate' |
| 100 | + ]) |
| 101 | + ->getMock(); |
| 102 | + |
| 103 | + $operations = new Operations($imageMock); |
| 104 | + |
| 105 | + $imageMock->expects($this->once()) |
| 106 | + ->method('rotate') |
| 107 | + ->with(90); |
| 108 | + |
| 109 | + $operations->rotate(['angle' => 90]); |
| 110 | + |
| 111 | + $this->expectException(\InvalidArgumentException::class); |
| 112 | + $this->expectExceptionMessage('Missing angle'); |
| 113 | + $operations->rotate([]); |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * @return void |
| 118 | + */ |
| 119 | + public function testSharpen(): void |
| 120 | + { |
| 121 | + $imageMock = $this->getMockBuilder(Image::class) |
| 122 | + ->addMethods([ |
| 123 | + 'sharpen' |
| 124 | + ]) |
| 125 | + ->getMock(); |
| 126 | + |
| 127 | + $operations = new Operations($imageMock); |
| 128 | + |
| 129 | + $imageMock->expects($this->once()) |
| 130 | + ->method('sharpen') |
| 131 | + ->with(90); |
| 132 | + |
| 133 | + $operations->sharpen(['amount' => 90]); |
| 134 | + |
| 135 | + $this->expectException(\InvalidArgumentException::class); |
| 136 | + $this->expectExceptionMessage('Missing amount'); |
| 137 | + $operations->sharpen([]); |
| 138 | + } |
| 139 | + |
| 140 | + /** |
| 141 | + * @return void |
| 142 | + */ |
| 143 | + public function testFit(): void |
| 144 | + { |
| 145 | + $imageMock = $this->getMockBuilder(Image::class) |
| 146 | + ->addMethods([ |
| 147 | + 'fit' |
| 148 | + ]) |
| 149 | + ->getMock(); |
| 150 | + |
| 151 | + $operations = new Operations($imageMock); |
| 152 | + |
| 153 | + $imageMock->expects($this->once()) |
| 154 | + ->method('fit') |
| 155 | + ->with(100); |
| 156 | + |
| 157 | + $operations->fit(['width' => 100]); |
| 158 | + |
| 159 | + $this->expectException(\InvalidArgumentException::class); |
| 160 | + $this->expectExceptionMessage('Missing width'); |
| 161 | + $operations->fit([]); |
| 162 | + } |
| 163 | + |
| 164 | + /** |
| 165 | + * @return void |
| 166 | + */ |
| 167 | + public function testCrop(): void |
| 168 | + { |
| 169 | + $imageMock = $this->getMockBuilder(Image::class) |
| 170 | + ->addMethods([ |
| 171 | + 'crop' |
| 172 | + ]) |
| 173 | + ->getMock(); |
| 174 | + |
| 175 | + $operations = new Operations($imageMock); |
| 176 | + |
| 177 | + $imageMock->expects($this->once()) |
| 178 | + ->method('crop') |
| 179 | + ->with(100); |
| 180 | + |
| 181 | + $operations->crop(['width' => 100, 'height' => 200]); |
| 182 | + |
| 183 | + $this->expectException(\InvalidArgumentException::class); |
| 184 | + $this->expectExceptionMessage('Missing width or height'); |
| 185 | + $operations->crop([]); |
| 186 | + } |
| 187 | +} |
0 commit comments