Skip to content

Commit d4f6f68

Browse files
committed
Fixed unit tests
1 parent c778c79 commit d4f6f68

10 files changed

Lines changed: 292 additions & 72 deletions

File tree

tests/Bridge/Nette/DI/ImageStorageExtensionTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ public function testExtensionShouldBeIntegratedWithMinimalConfiguration(): void
146146
Applicator\Orientation::class,
147147
Applicator\Resize::class,
148148
Applicator\Format::class,
149+
Applicator\StripMeta::class,
149150
],
150151
validatorTypes: [
151152
Validator\AllowedResolutionValidator::class,
@@ -250,6 +251,7 @@ public function testExtensionShouldBeIntegratedWithCustomModifiersAndApplicators
250251
Applicator\Orientation::class,
251252
Applicator\Resize::class,
252253
Applicator\Format::class,
254+
Applicator\StripMeta::class,
253255
],
254256
validatorTypes: [
255257
TestValidator::class,

tests/Fixtures/TestApplicator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
final class TestApplicator implements ModifierApplicatorInterface
1414
{
15-
public function apply(Image $image, PathInfoInterface $pathInfo, ModifierValues $values, ConfigInterface $config): Image
15+
public function apply(Image $image, PathInfoInterface $pathInfo, ModifierValues $values, ConfigInterface $config): iterable
1616
{
17+
return [];
1718
}
1819
}

tests/Modifier/Applicator/FormatTest.phpt

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ final class FormatTest extends TestCase
3636

3737
$applicator = new Format();
3838

39-
Assert::null($applicator->apply($image, $pathInfo, $modifierValues, $config));
39+
Assert::same([], iterator_to_array($applicator->apply($image, $pathInfo, $modifierValues, $config)));
4040
}
4141

4242
public function testNullShouldBeReturnedIfQualityIsNotSpecifiedAndPathInfoExtensionIsNull(): void
@@ -52,58 +52,50 @@ final class FormatTest extends TestCase
5252

5353
$applicator = new Format();
5454

55-
Assert::null($applicator->apply($image, $pathInfo, $modifierValues, $config));
55+
Assert::same([], iterator_to_array($applicator->apply($image, $pathInfo, $modifierValues, $config)));
5656
}
5757

5858
public function testImageShouldBeEncodedInDefaultFormatIfPathInfoExtensionIsNullAndImageMimeTypeIsUnsupported(): void
5959
{
6060
$image = Mockery::mock(Image::class);
6161
$pathInfo = $this->createPathInfo(null);
6262
$modifierValues = $this->createModifierValues(null);
63-
$config = $this->createConfigForEncode();
63+
$config = Mockery::mock(ConfigInterface::class);
6464

6565
$image->shouldReceive('mime')
6666
->withNoArgs()
6767
->andReturn('image/unsupported');
6868

6969
$modifiedImage = $this->setupJpgExpectationsOnImage($image, false);
7070

71-
$modifiedImage->shouldReceive('encode')
72-
->once()
73-
->with('jpg', 90)
74-
->andReturn($modifiedImage);
75-
7671
$applicator = new Format();
7772

78-
Assert::same($modifiedImage, $applicator->apply($image, $pathInfo, $modifierValues, $config));
73+
$result = iterator_to_array($applicator->apply($image, $pathInfo, $modifierValues, $config));
74+
Assert::same($modifiedImage, $result['image']);
75+
Assert::same('jpg', $result['format']);
7976
}
8077

8178
public function testImageShouldBeEncodedIfPathInfoExtensionIsDifferentThanImageMimeType(): void
8279
{
8380
$image = Mockery::mock(Image::class);
84-
$modifiedImage = Mockery::mock(Image::class);
8581
$pathInfo = $this->createPathInfo('webp');
8682
$modifierValues = $this->createModifierValues(null);
87-
$config = $this->createConfigForEncode();
83+
$config = Mockery::mock(ConfigInterface::class);
8884

8985
$image->shouldReceive('mime')
9086
->withNoArgs()
9187
->andReturn('image/jpeg');
9288

93-
$image->shouldReceive('encode')
94-
->once()
95-
->with('webp', 90)
96-
->andReturn($modifiedImage);
97-
9889
$applicator = new Format();
9990

100-
Assert::same($modifiedImage, $applicator->apply($image, $pathInfo, $modifierValues, $config));
91+
$result = iterator_to_array($applicator->apply($image, $pathInfo, $modifierValues, $config));
92+
Assert::same($image, $result['image']);
93+
Assert::same('webp', $result['format']);
10194
}
10295

10396
public function testImageShouldBeEncodedIfQualityIsSpecified(): void
10497
{
10598
$image = Mockery::mock(Image::class);
106-
$modifiedImage = Mockery::mock(Image::class);
10799
$pathInfo = $this->createPathInfo(null);
108100
$modifierValues = $this->createModifierValues(75);
109101
$config = Mockery::mock(ConfigInterface::class);
@@ -112,37 +104,32 @@ final class FormatTest extends TestCase
112104
->withNoArgs()
113105
->andReturn('image/png');
114106

115-
$image->shouldReceive('encode')
116-
->once()
117-
->with('png', 75)
118-
->andReturn($modifiedImage);
119-
120107
$applicator = new Format();
121108

122-
Assert::same($modifiedImage, $applicator->apply($image, $pathInfo, $modifierValues, $config));
109+
$result = iterator_to_array($applicator->apply($image, $pathInfo, $modifierValues, $config));
110+
Assert::same($image, $result['image']);
111+
Assert::same('png', $result['format']);
112+
Assert::same(75, $result['quality']);
123113
}
124114

125115
public function testImageShouldBeEncodedToJpegFromDifferentFormat(): void
126116
{
127117
$image = Mockery::mock(Image::class);
128118
$pathInfo = $this->createPathInfo('jpg');
129119
$modifierValues = $this->createModifierValues(null);
130-
$config = $this->createConfigForEncode();
120+
$config = Mockery::mock(ConfigInterface::class);
131121

132122
$image->shouldReceive('mime')
133123
->withNoArgs()
134124
->andReturn('image/png');
135125

136126
$modifiedImage = $this->setupJpgExpectationsOnImage($image, false);
137127

138-
$modifiedImage->shouldReceive('encode')
139-
->once()
140-
->with('jpg', 90)
141-
->andReturn($modifiedImage);
142-
143128
$applicator = new Format();
144129

145-
Assert::same($modifiedImage, $applicator->apply($image, $pathInfo, $modifierValues, $config));
130+
$result = iterator_to_array($applicator->apply($image, $pathInfo, $modifierValues, $config));
131+
Assert::same($modifiedImage, $result['image']);
132+
Assert::same('jpg', $result['format']);
146133
}
147134

148135
/**
@@ -153,7 +140,7 @@ final class FormatTest extends TestCase
153140
$image = Mockery::mock(Image::class);
154141
$pathInfo = $this->createPathInfo('pjpg');
155142
$modifierValues = $this->createModifierValues(null);
156-
$config = $this->createConfigForEncode();
143+
$config = Mockery::mock(ConfigInterface::class);
157144

158145
$image->shouldReceive('mime')
159146
->withNoArgs()
@@ -165,14 +152,11 @@ final class FormatTest extends TestCase
165152

166153
$modifiedImage = $this->setupJpgExpectationsOnImage($image, true);
167154

168-
$modifiedImage->shouldReceive('encode')
169-
->once()
170-
->with('jpg', 90)
171-
->andReturn($modifiedImage);
172-
173155
$applicator = new Format();
174156

175-
Assert::same($modifiedImage, $applicator->apply($image, $pathInfo, $modifierValues, $config));
157+
$result = iterator_to_array($applicator->apply($image, $pathInfo, $modifierValues, $config));
158+
Assert::same($modifiedImage, $result['image']);
159+
Assert::same('jpg', $result['format']);
176160
}
177161

178162
public function testImageShouldNotBeEncodedToProgressiveJpeg(): void
@@ -198,7 +182,7 @@ final class FormatTest extends TestCase
198182

199183
$applicator = new Format();
200184

201-
Assert::null($applicator->apply($image, $pathInfo, $modifierValues, $config));
185+
Assert::same([], iterator_to_array($applicator->apply($image, $pathInfo, $modifierValues, $config)));
202186
}
203187

204188
public function provideImageCoresForProgressiveJpegWithInvalidInterlaceScheme(): array

tests/Modifier/Applicator/OrientationTest.phpt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ final class OrientationTest extends TestCase
3232

3333
$applicator = new Orientation();
3434

35-
Assert::null($applicator->apply($image, $pathInfo, $modifierValues, $config));
35+
Assert::same([], iterator_to_array($applicator->apply($image, $pathInfo, $modifierValues, $config)));
3636
}
3737

3838
/**
@@ -58,7 +58,7 @@ final class OrientationTest extends TestCase
5858

5959
$applicator = new Orientation();
6060

61-
Assert::null($applicator->apply($image, $pathInfo, $modifierValues, $config));
61+
Assert::same([], iterator_to_array($applicator->apply($image, $pathInfo, $modifierValues, $config)));
6262
}
6363

6464
/**
@@ -89,7 +89,8 @@ final class OrientationTest extends TestCase
8989

9090
$applicator = new Orientation();
9191

92-
Assert::same($modifiedImage, $applicator->apply($image, $pathInfo, $modifierValues, $config));
92+
$result = iterator_to_array($applicator->apply($image, $pathInfo, $modifierValues, $config));
93+
Assert::same($modifiedImage, $result['image']);
9394
}
9495

9596
public function testImageShouldBeRotated(): void
@@ -112,7 +113,8 @@ final class OrientationTest extends TestCase
112113

113114
$applicator = new Orientation();
114115

115-
Assert::same($modifiedImage, $applicator->apply($image, $pathInfo, $modifierValues, $config));
116+
$result = iterator_to_array($applicator->apply($image, $pathInfo, $modifierValues, $config));
117+
Assert::same($modifiedImage, $result['image']);
116118
}
117119

118120
public function provideNormalExifOrientations(): array

tests/Modifier/Applicator/ResizeTest.phpt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ final class ResizeTest extends TestCase
3636
$applicator = new Resize();
3737

3838
Assert::exception(
39-
static fn () => $applicator->apply($image, $pathInfo, $modifierValues, $config),
39+
static fn () => iterator_to_array($applicator->apply($image, $pathInfo, $modifierValues, $config)),
4040
ModifierException::class,
4141
'The only one dimension (width or height) must be defined if an aspect ratio is used. Passed values: w=null, h=null, ar=16x9.',
4242
);
@@ -52,7 +52,7 @@ final class ResizeTest extends TestCase
5252
$applicator = new Resize();
5353

5454
Assert::exception(
55-
static fn () => $applicator->apply($image, $pathInfo, $modifierValues, $config),
55+
static fn () => iterator_to_array($applicator->apply($image, $pathInfo, $modifierValues, $config)),
5656
ModifierException::class,
5757
'The only one dimension (width or height) must be defined if an aspect ratio is used. Passed values: w=100, h=200, ar=16x9.',
5858
);
@@ -80,7 +80,7 @@ final class ResizeTest extends TestCase
8080

8181
$applicator = new Resize();
8282

83-
Assert::null($applicator->apply($image, $pathInfo, $modifierValues, $config));
83+
Assert::same([], iterator_to_array($applicator->apply($image, $pathInfo, $modifierValues, $config)));
8484
}
8585

8686
public function testImageShouldBeModifiedWithContainFit(): void
@@ -118,7 +118,8 @@ final class ResizeTest extends TestCase
118118

119119
$applicator = new Resize();
120120

121-
Assert::same($image, $applicator->apply($image, $pathInfo, $modifierValues, $config));
121+
$result = iterator_to_array($applicator->apply($image, $pathInfo, $modifierValues, $config));
122+
Assert::same($image, $result['image']);
122123
}
123124

124125
public function testImageShouldBeModifiedWithStretchFit(): void
@@ -145,7 +146,8 @@ final class ResizeTest extends TestCase
145146

146147
$applicator = new Resize();
147148

148-
Assert::same($image, $applicator->apply($image, $pathInfo, $modifierValues, $config));
149+
$result = iterator_to_array($applicator->apply($image, $pathInfo, $modifierValues, $config));
150+
Assert::same($image, $result['image']);
149151
}
150152

151153
public function testImageShouldBeModifiedWithFillFit(): void
@@ -200,7 +202,8 @@ final class ResizeTest extends TestCase
200202

201203
$applicator = new Resize();
202204

203-
Assert::same($image, $applicator->apply($image, $pathInfo, $modifierValues, $config));
205+
$result = iterator_to_array($applicator->apply($image, $pathInfo, $modifierValues, $config));
206+
Assert::same($image, $result['image']);
204207
}
205208

206209
public function testImageShouldBeModifiedWithCropFit(): void
@@ -227,7 +230,8 @@ final class ResizeTest extends TestCase
227230

228231
$applicator = new Resize();
229232

230-
Assert::same($image, $applicator->apply($image, $pathInfo, $modifierValues, $config));
233+
$result = iterator_to_array($applicator->apply($image, $pathInfo, $modifierValues, $config));
234+
Assert::same($image, $result['image']);
231235
}
232236

233237
public function getSameImageDimensionsData(): array

0 commit comments

Comments
 (0)