@@ -130,6 +130,11 @@ class ImageResizeTest extends TestCase
130
130
*/
131
131
private $ storeManager ;
132
132
133
+ /**
134
+ * @var string
135
+ */
136
+ private $ testImageHiddenfilepath ;
137
+
133
138
/**
134
139
* @inheritDoc
135
140
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
@@ -139,6 +144,8 @@ protected function setUp(): void
139
144
$ this ->testfilename = "image.jpg " ;
140
145
$ this ->testImageHiddenFilename = "image_hidden.jpg " ;
141
146
$ this ->testfilepath = "/image.jpg " ;
147
+ $ this ->testImageHiddenfilepath = "/image_hidden.jpg " ;
148
+
142
149
143
150
$ this ->appStateMock = $ this ->createMock (State::class);
144
151
$ this ->imageConfigMock = $ this ->createMock (MediaConfig::class);
@@ -167,7 +174,7 @@ protected function setUp(): void
167
174
168
175
$ this ->assetImageMock ->expects ($ this ->any ())
169
176
->method ('getPath ' )
170
- ->willReturn ($ this ->testfilepath );
177
+ ->willReturnOnConsecutiveCalls ($ this ->testfilepath , $ this -> testImageHiddenfilepath );
171
178
$ this ->assetImageFactoryMock ->expects ($ this ->any ())
172
179
->method ('create ' )
173
180
->willReturn ($ this ->assetImageMock );
@@ -189,16 +196,16 @@ protected function setUp(): void
189
196
190
197
$ this ->imageConfigMock ->expects ($ this ->any ())
191
198
->method ('getMediaPath ' )
192
- ->with ( $ this ->testfilename )
193
- ->willReturn ($ this ->testfilepath );
199
+ ->withConsecutive ([ $ this ->testfilename ], [ $ this -> testImageHiddenFilename ] )
200
+ ->willReturnOnConsecutiveCalls ($ this ->testfilepath , $ this -> testImageHiddenfilepath );
194
201
$ this ->mediaDirectoryMock ->expects ($ this ->any ())
195
202
->method ('getAbsolutePath ' )
196
- ->with ( $ this ->testfilepath )
197
- ->willReturn ($ this ->testfilepath );
203
+ ->withConsecutive ([ $ this ->testfilepath ], [ $ this -> testImageHiddenfilepath ] )
204
+ ->willReturnOnConsecutiveCalls ($ this ->testfilepath , $ this -> testImageHiddenfilepath );
198
205
$ this ->mediaDirectoryMock ->expects ($ this ->any ())
199
206
->method ('getRelativePath ' )
200
- ->with ($ this ->testfilepath )
201
- ->willReturn ($ this ->testfilepath );
207
+ ->willReturnOnConsecutiveCalls ($ this ->testfilepath , $ this -> testImageHiddenfilepath )
208
+ ->willReturnOnConsecutiveCalls ($ this ->testfilepath , $ this -> testImageHiddenfilepath );
202
209
203
210
$ this ->viewMock ->expects ($ this ->any ())
204
211
->method ('getMediaEntities ' )
@@ -255,7 +262,7 @@ public function testResizeFromThemesMediaStorageDatabase()
255
262
->willReturn (false );
256
263
257
264
$ imageMock = $ this ->createMock (Image::class);
258
- $ this ->imageFactoryMock ->expects ($ this ->once ())
265
+ $ this ->imageFactoryMock ->expects ($ this ->any ())
259
266
->method ('create ' )
260
267
->willReturn ($ imageMock );
261
268
@@ -275,15 +282,15 @@ function () {
275
282
276
283
$ this ->mediaDirectoryMock ->expects ($ this ->any ())
277
284
->method ('isFile ' )
278
- ->with ( $ this ->testfilepath )
285
+ ->withConsecutive ([ $ this ->testfilepath ], [ $ this -> testImageHiddenfilepath ] )
279
286
->willReturn (true );
280
287
281
- $ this ->databaseMock ->expects ($ this ->once ())
288
+ $ this ->databaseMock ->expects ($ this ->any ())
282
289
->method ('saveFileToFilesystem ' )
283
- ->with ( $ this ->testfilepath );
284
- $ this ->databaseMock ->expects ($ this ->once ())
290
+ ->withConsecutive ([ $ this ->testfilepath ], [ $ this -> testImageHiddenfilepath ] );
291
+ $ this ->databaseMock ->expects ($ this ->any ())
285
292
->method ('saveFile ' )
286
- ->with ( $ this ->testfilepath );
293
+ ->withConsecutive ([ $ this ->testfilepath ], [ $ this -> testImageHiddenfilepath ] );
287
294
288
295
$ generator = $ this ->service ->resizeFromThemes (['test-theme ' ], true );
289
296
while ($ generator ->valid ()) {
@@ -304,7 +311,7 @@ public function testResizeFromThemesHiddenImagesMediaStorageDatabase()
304
311
->willReturn (false );
305
312
306
313
$ imageMock = $ this ->createMock (Image::class);
307
- $ this ->imageFactoryMock ->expects ($ this ->once ())
314
+ $ this ->imageFactoryMock ->expects ($ this ->any ())
308
315
->method ('create ' )
309
316
->willReturn ($ imageMock );
310
317
@@ -338,15 +345,15 @@ function () {
338
345
339
346
$ this ->mediaDirectoryMock ->expects ($ this ->any ())
340
347
->method ('isFile ' )
341
- ->with ( $ this ->testfilepath )
348
+ ->withConsecutive ([ $ this ->testfilepath ], [ $ this -> testImageHiddenfilepath ] )
342
349
->willReturn (true );
343
350
344
- $ this ->databaseMock ->expects ($ this ->once ())
351
+ $ this ->databaseMock ->expects ($ this ->any ())
345
352
->method ('saveFileToFilesystem ' )
346
- ->with ( $ this ->testfilepath );
347
- $ this ->databaseMock ->expects ($ this ->once ())
353
+ ->withConsecutive ([ $ this ->testfilepath ], [ $ this -> testImageHiddenfilepath ] );
354
+ $ this ->databaseMock ->expects ($ this ->any ())
348
355
->method ('saveFile ' )
349
- ->with ( $ this ->testfilepath );
356
+ ->withConsecutive ([ $ this ->testfilepath ], [ $ this -> testImageHiddenfilepath ] );
350
357
351
358
$ this ->assertEquals (2 , $ this ->service ->getCountProductImages ());
352
359
$ this ->assertEquals (1 , $ this ->service ->getCountProductImages (true ));
@@ -370,7 +377,7 @@ public function testResizeFromThemesUnsupportedImage()
370
377
->method ('fileExists ' )
371
378
->willReturn (false );
372
379
373
- $ this ->imageFactoryMock ->expects ($ this ->once ())
380
+ $ this ->imageFactoryMock ->expects ($ this ->any ())
374
381
->method ('create ' )
375
382
->willThrowException (new \InvalidArgumentException ('Unsupported image format. ' ));
376
383
@@ -390,7 +397,7 @@ function () {
390
397
391
398
$ this ->mediaDirectoryMock ->expects ($ this ->any ())
392
399
->method ('isFile ' )
393
- ->with ( $ this ->testfilepath )
400
+ ->withConsecutive ([ $ this ->testfilepath ], [ $ this -> testImageHiddenfilepath ] )
394
401
->willReturn (true );
395
402
396
403
$ generator = $ this ->service ->resizeFromThemes (['test-theme ' ], true );
@@ -411,13 +418,13 @@ public function testResizeFromImageNameMediaStorageDatabase()
411
418
->willReturn (false );
412
419
413
420
$ imageMock = $ this ->createMock (Image::class);
414
- $ this ->imageFactoryMock ->expects ($ this ->once ())
421
+ $ this ->imageFactoryMock ->expects ($ this ->any ())
415
422
->method ('create ' )
416
423
->willReturn ($ imageMock );
417
424
418
425
$ this ->mediaDirectoryMock ->expects ($ this ->any ())
419
426
->method ('isFile ' )
420
- ->with ( $ this ->testfilepath )
427
+ ->withConsecutive ([ $ this ->testfilepath ], [ $ this -> testImageHiddenfilepath ] )
421
428
->willReturnOnConsecutiveCalls (
422
429
$ this ->returnValue (false ),
423
430
$ this ->returnValue (true )
@@ -434,12 +441,12 @@ public function testResizeFromImageNameMediaStorageDatabase()
434
441
['0 ' => []]
435
442
);
436
443
437
- $ this ->databaseMock ->expects ($ this ->once ())
444
+ $ this ->databaseMock ->expects ($ this ->any ())
438
445
->method ('saveFileToFilesystem ' )
439
- ->with ( $ this ->testfilepath );
440
- $ this ->databaseMock ->expects ($ this ->once ())
446
+ ->withConsecutive ([ $ this ->testfilepath ], [ $ this -> testImageHiddenfilepath ] );
447
+ $ this ->databaseMock ->expects ($ this ->any ())
441
448
->method ('saveFile ' )
442
- ->with ( $ this ->testfilepath );
449
+ ->withConsecutive ([ $ this ->testfilepath ], [ $ this -> testImageHiddenfilepath ] );
443
450
444
451
$ this ->service ->resizeFromImageName ($ this ->testfilename );
445
452
}
@@ -482,7 +489,7 @@ public function testSkipResizingAlreadyResizedImageInDatabase()
482
489
483
490
$ this ->mediaDirectoryMock ->expects ($ this ->any ())
484
491
->method ('isFile ' )
485
- ->with ( $ this ->testfilepath )
492
+ ->withConsecutive ([ $ this ->testfilepath ], [ $ this -> testImageHiddenfilepath ] )
486
493
->willReturnOnConsecutiveCalls (
487
494
$ this ->returnValue (false ),
488
495
$ this ->returnValue (true )
0 commit comments