Skip to content

Commit e60df84

Browse files
committed
Adding tests for operations
1 parent 55f4a1b commit e60df84

File tree

3 files changed

+192
-2
lines changed

3 files changed

+192
-2
lines changed

src/Operations.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ static function ($constraint) use ($preventUpscale) {
8484
public function crop(array $arguments): void
8585
{
8686
if (!isset($arguments['height'], $arguments['width'])) {
87-
throw new InvalidArgumentException('Missing height or width');
87+
throw new InvalidArgumentException('Missing width or height');
8888
}
8989

90+
$arguments = array_merge(['x' => null, 'y' => null], $arguments);
9091
$height = $arguments['height'] ? (int)$arguments['height'] : null;
9192
$width = $arguments['width'] ? (int)$arguments['width'] : null;
9293
$x = $arguments['x'] ? (int)$arguments['x'] : null;

tests/TestCase/Processor/Image/ImageProcessorTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818

1919
use Intervention\Image\Image;
2020
use Intervention\Image\ImageManager;
21+
use Phauthentic\Infrastructure\Storage\File;
2122
use Phauthentic\Infrastructure\Storage\FileFactory;
2223
use Phauthentic\Infrastructure\Storage\FileStorageInterface;
2324
use Phauthentic\Infrastructure\Storage\PathBuilder\PathBuilder;
24-
use Phauthentic\Infrastructure\Storage\PathBuilder\PathBuilderInterface;
2525
use Phauthentic\Infrastructure\Storage\Processor\Image\ImageVariantCollection;
2626
use Phauthentic\Infrastructure\Storage\Processor\Image\ImageProcessor;
2727
use Phauthentic\Test\TestCase\TestCase;
@@ -75,5 +75,7 @@ public function testProcessor(): void
7575
$file = $file->withVariants($collection->toArray());
7676

7777
$file = $processor->process($file);
78+
79+
$this->assertInstanceOf(File::class, $file);
7880
}
7981
}
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
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

Comments
 (0)