@@ -60,11 +60,6 @@ class ImageResizeTest extends TestCase
6060 */
6161 protected $ imageFactoryMock ;
6262
63- /**
64- * @var Image|MockObject
65- */
66- protected $ imageMock ;
67-
6863 /**
6964 * @var ParamsBuilder|MockObject
7065 */
@@ -141,7 +136,6 @@ protected function setUp(): void
141136 $ this ->appStateMock = $ this ->createMock (State::class);
142137 $ this ->imageConfigMock = $ this ->createMock (MediaConfig::class);
143138 $ this ->productImageMock = $ this ->createMock (ProductImage::class);
144- $ this ->imageMock = $ this ->createMock (Image::class);
145139 $ this ->imageFactoryMock = $ this ->createMock (ImageFactory::class);
146140 $ this ->paramsBuilderMock = $ this ->createMock (ParamsBuilder::class);
147141 $ this ->viewMock = $ this ->createMock (View::class);
@@ -164,9 +158,6 @@ protected function setUp(): void
164158 ->with (DirectoryList::MEDIA )
165159 ->willReturn ($ this ->mediaDirectoryMock );
166160
167- $ this ->imageFactoryMock ->expects ($ this ->any ())
168- ->method ('create ' )
169- ->willReturn ($ this ->imageMock );
170161 $ this ->assetImageMock ->expects ($ this ->any ())
171162 ->method ('getPath ' )
172163 ->willReturn ($ this ->testfilepath );
@@ -256,6 +247,11 @@ public function testResizeFromThemesMediaStorageDatabase()
256247 ->method ('fileExists ' )
257248 ->willReturn (false );
258249
250+ $ imageMock = $ this ->createMock (Image::class);
251+ $ this ->imageFactoryMock ->expects ($ this ->once ())
252+ ->method ('create ' )
253+ ->willReturn ($ imageMock );
254+
259255 $ this ->productImageMock ->expects ($ this ->any ())
260256 ->method ('getCountUsedProductImages ' )
261257 ->willReturn (1 );
@@ -284,6 +280,49 @@ function () {
284280
285281 $ generator = $ this ->service ->resizeFromThemes (['test-theme ' ]);
286282 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 ' ]);
287326 $ generator ->next ();
288327 }
289328 }
@@ -297,6 +336,11 @@ public function testResizeFromImageNameMediaStorageDatabase()
297336 ->method ('fileExists ' )
298337 ->willReturn (false );
299338
339+ $ imageMock = $ this ->createMock (Image::class);
340+ $ this ->imageFactoryMock ->expects ($ this ->once ())
341+ ->method ('create ' )
342+ ->willReturn ($ imageMock );
343+
300344 $ this ->mediaDirectoryMock ->expects ($ this ->any ())
301345 ->method ('isFile ' )
302346 ->with ($ this ->testfilepath )
0 commit comments