@@ -60,11 +60,6 @@ class ImageResizeTest extends TestCase
60
60
*/
61
61
protected $ imageFactoryMock ;
62
62
63
- /**
64
- * @var Image|MockObject
65
- */
66
- protected $ imageMock ;
67
-
68
63
/**
69
64
* @var ParamsBuilder|MockObject
70
65
*/
@@ -141,7 +136,6 @@ protected function setUp(): void
141
136
$ this ->appStateMock = $ this ->createMock (State::class);
142
137
$ this ->imageConfigMock = $ this ->createMock (MediaConfig::class);
143
138
$ this ->productImageMock = $ this ->createMock (ProductImage::class);
144
- $ this ->imageMock = $ this ->createMock (Image::class);
145
139
$ this ->imageFactoryMock = $ this ->createMock (ImageFactory::class);
146
140
$ this ->paramsBuilderMock = $ this ->createMock (ParamsBuilder::class);
147
141
$ this ->viewMock = $ this ->createMock (View::class);
@@ -164,9 +158,6 @@ protected function setUp(): void
164
158
->with (DirectoryList::MEDIA )
165
159
->willReturn ($ this ->mediaDirectoryMock );
166
160
167
- $ this ->imageFactoryMock ->expects ($ this ->any ())
168
- ->method ('create ' )
169
- ->willReturn ($ this ->imageMock );
170
161
$ this ->assetImageMock ->expects ($ this ->any ())
171
162
->method ('getPath ' )
172
163
->willReturn ($ this ->testfilepath );
@@ -256,6 +247,11 @@ public function testResizeFromThemesMediaStorageDatabase()
256
247
->method ('fileExists ' )
257
248
->willReturn (false );
258
249
250
+ $ imageMock = $ this ->createMock (Image::class);
251
+ $ this ->imageFactoryMock ->expects ($ this ->once ())
252
+ ->method ('create ' )
253
+ ->willReturn ($ imageMock );
254
+
259
255
$ this ->productImageMock ->expects ($ this ->any ())
260
256
->method ('getCountUsedProductImages ' )
261
257
->willReturn (1 );
@@ -284,6 +280,49 @@ function () {
284
280
285
281
$ generator = $ this ->service ->resizeFromThemes (['test-theme ' ]);
286
282
while ($ generator ->valid ()) {
283
+ $ resizeInfo = $ generator ->key ();
284
+ $ this ->assertEquals ('image.jpg ' , $ resizeInfo ['filename ' ]);
285
+ $ this ->assertEmpty ($ resizeInfo ['error ' ]);
286
+ $ generator ->next ();
287
+ }
288
+ }
289
+
290
+ public function testResizeFromThemesUnsupportedImage ()
291
+ {
292
+ $ this ->databaseMock ->expects ($ this ->any ())
293
+ ->method ('checkDbUsage ' )
294
+ ->willReturn (true );
295
+ $ this ->databaseMock ->expects ($ this ->any ())
296
+ ->method ('fileExists ' )
297
+ ->willReturn (false );
298
+
299
+ $ this ->imageFactoryMock ->expects ($ this ->once ())
300
+ ->method ('create ' )
301
+ ->willThrowException (new \InvalidArgumentException ('Unsupported image format. ' ));
302
+
303
+ $ this ->productImageMock ->expects ($ this ->any ())
304
+ ->method ('getCountUsedProductImages ' )
305
+ ->willReturn (1 );
306
+ $ this ->productImageMock ->expects ($ this ->any ())
307
+ ->method ('getUsedProductImages ' )
308
+ ->willReturnCallback (
309
+ function () {
310
+ $ data = [[ 'filepath ' => $ this ->testfilename ]];
311
+ foreach ($ data as $ e ) {
312
+ yield $ e ;
313
+ }
314
+ }
315
+ );
316
+
317
+ $ this ->mediaDirectoryMock ->expects ($ this ->any ())
318
+ ->method ('isFile ' )
319
+ ->with ($ this ->testfilepath )
320
+ ->willReturn (true );
321
+
322
+ $ generator = $ this ->service ->resizeFromThemes (['test-theme ' ]);
323
+ while ($ generator ->valid ()) {
324
+ $ resizeInfo = $ generator ->key ();
325
+ $ this ->assertEquals ('Unsupported image format. ' , $ resizeInfo ['error ' ]);
287
326
$ generator ->next ();
288
327
}
289
328
}
@@ -297,6 +336,11 @@ public function testResizeFromImageNameMediaStorageDatabase()
297
336
->method ('fileExists ' )
298
337
->willReturn (false );
299
338
339
+ $ imageMock = $ this ->createMock (Image::class);
340
+ $ this ->imageFactoryMock ->expects ($ this ->once ())
341
+ ->method ('create ' )
342
+ ->willReturn ($ imageMock );
343
+
300
344
$ this ->mediaDirectoryMock ->expects ($ this ->any ())
301
345
->method ('isFile ' )
302
346
->with ($ this ->testfilepath )
0 commit comments