Skip to content

Commit d16ee89

Browse files
committed
#28239: resize command does not process hidden images
- Fixed Unit Test - Removed unnecessary dependency in the constructor
1 parent c35cd1f commit d16ee89

File tree

2 files changed

+37
-38
lines changed

2 files changed

+37
-38
lines changed

app/code/Magento/MediaStorage/Console/Command/ImagesResizeCommand.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use Symfony\Component\Console\Output\OutputInterface;
1919
use Symfony\Component\Console\Input\InputOption;
2020
use Symfony\Component\Console\Command\Command;
21-
use Magento\Catalog\Model\ResourceModel\Product\Image as ProductImage;
21+
2222

2323
/**
2424
* Resizes product images according to theme view definitions.
@@ -55,11 +55,6 @@ class ImagesResizeCommand extends Command
5555
*/
5656
private $progressBarFactory;
5757

58-
/**
59-
* @var ProductImage
60-
*/
61-
private $productImage;
62-
6358
/**
6459
* @var bool
6560
*/
@@ -70,22 +65,19 @@ class ImagesResizeCommand extends Command
7065
* @param ImageResize $imageResize
7166
* @param ImageResizeScheduler $imageResizeScheduler
7267
* @param ProgressBarFactory $progressBarFactory
73-
* @param ProductImage $productImage
7468
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
7569
*/
7670
public function __construct(
7771
State $appState,
7872
ImageResize $imageResize,
7973
ImageResizeScheduler $imageResizeScheduler,
80-
ProgressBarFactory $progressBarFactory,
81-
ProductImage $productImage
74+
ProgressBarFactory $progressBarFactory
8275
) {
8376
parent::__construct();
8477
$this->appState = $appState;
8578
$this->imageResize = $imageResize;
8679
$this->imageResizeScheduler = $imageResizeScheduler;
8780
$this->progressBarFactory = $progressBarFactory;
88-
$this->productImage = $productImage;
8981
}
9082

9183
/**

app/code/Magento/MediaStorage/Test/Unit/Service/ImageResizeTest.php

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ class ImageResizeTest extends TestCase
130130
*/
131131
private $storeManager;
132132

133+
/**
134+
* @var string
135+
*/
136+
private $testImageHiddenfilepath;
137+
133138
/**
134139
* @inheritDoc
135140
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
@@ -139,6 +144,8 @@ protected function setUp(): void
139144
$this->testfilename = "image.jpg";
140145
$this->testImageHiddenFilename = "image_hidden.jpg";
141146
$this->testfilepath = "/image.jpg";
147+
$this->testImageHiddenfilepath = "/image_hidden.jpg";
148+
142149

143150
$this->appStateMock = $this->createMock(State::class);
144151
$this->imageConfigMock = $this->createMock(MediaConfig::class);
@@ -167,7 +174,7 @@ protected function setUp(): void
167174

168175
$this->assetImageMock->expects($this->any())
169176
->method('getPath')
170-
->willReturn($this->testfilepath);
177+
->willReturnOnConsecutiveCalls($this->testfilepath, $this->testImageHiddenfilepath);
171178
$this->assetImageFactoryMock->expects($this->any())
172179
->method('create')
173180
->willReturn($this->assetImageMock);
@@ -189,16 +196,16 @@ protected function setUp(): void
189196

190197
$this->imageConfigMock->expects($this->any())
191198
->method('getMediaPath')
192-
->with($this->testfilename)
193-
->willReturn($this->testfilepath);
199+
->withConsecutive([$this->testfilename], [$this->testImageHiddenFilename])
200+
->willReturnOnConsecutiveCalls($this->testfilepath, $this->testImageHiddenfilepath);
194201
$this->mediaDirectoryMock->expects($this->any())
195202
->method('getAbsolutePath')
196-
->with($this->testfilepath)
197-
->willReturn($this->testfilepath);
203+
->withConsecutive([$this->testfilepath], [$this->testImageHiddenfilepath])
204+
->willReturnOnConsecutiveCalls($this->testfilepath, $this->testImageHiddenfilepath);
198205
$this->mediaDirectoryMock->expects($this->any())
199206
->method('getRelativePath')
200-
->with($this->testfilepath)
201-
->willReturn($this->testfilepath);
207+
->willReturnOnConsecutiveCalls($this->testfilepath, $this->testImageHiddenfilepath)
208+
->willReturnOnConsecutiveCalls($this->testfilepath, $this->testImageHiddenfilepath);
202209

203210
$this->viewMock->expects($this->any())
204211
->method('getMediaEntities')
@@ -255,7 +262,7 @@ public function testResizeFromThemesMediaStorageDatabase()
255262
->willReturn(false);
256263

257264
$imageMock = $this->createMock(Image::class);
258-
$this->imageFactoryMock->expects($this->once())
265+
$this->imageFactoryMock->expects($this->any())
259266
->method('create')
260267
->willReturn($imageMock);
261268

@@ -275,15 +282,15 @@ function () {
275282

276283
$this->mediaDirectoryMock->expects($this->any())
277284
->method('isFile')
278-
->with($this->testfilepath)
285+
->withConsecutive([$this->testfilepath], [$this->testImageHiddenfilepath])
279286
->willReturn(true);
280287

281-
$this->databaseMock->expects($this->once())
288+
$this->databaseMock->expects($this->any())
282289
->method('saveFileToFilesystem')
283-
->with($this->testfilepath);
284-
$this->databaseMock->expects($this->once())
290+
->withConsecutive([$this->testfilepath], [$this->testImageHiddenfilepath]);
291+
$this->databaseMock->expects($this->any())
285292
->method('saveFile')
286-
->with($this->testfilepath);
293+
->withConsecutive([$this->testfilepath], [$this->testImageHiddenfilepath]);
287294

288295
$generator = $this->service->resizeFromThemes(['test-theme'], true);
289296
while ($generator->valid()) {
@@ -304,7 +311,7 @@ public function testResizeFromThemesHiddenImagesMediaStorageDatabase()
304311
->willReturn(false);
305312

306313
$imageMock = $this->createMock(Image::class);
307-
$this->imageFactoryMock->expects($this->once())
314+
$this->imageFactoryMock->expects($this->any())
308315
->method('create')
309316
->willReturn($imageMock);
310317

@@ -338,15 +345,15 @@ function () {
338345

339346
$this->mediaDirectoryMock->expects($this->any())
340347
->method('isFile')
341-
->with($this->testfilepath)
348+
->withConsecutive([$this->testfilepath], [$this->testImageHiddenfilepath])
342349
->willReturn(true);
343350

344-
$this->databaseMock->expects($this->once())
351+
$this->databaseMock->expects($this->any())
345352
->method('saveFileToFilesystem')
346-
->with($this->testfilepath);
347-
$this->databaseMock->expects($this->once())
353+
->withConsecutive([$this->testfilepath], [$this->testImageHiddenfilepath]);
354+
$this->databaseMock->expects($this->any())
348355
->method('saveFile')
349-
->with($this->testfilepath);
356+
->withConsecutive([$this->testfilepath], [$this->testImageHiddenfilepath]);
350357

351358
$this->assertEquals(2, $this->service->getCountProductImages());
352359
$this->assertEquals(1, $this->service->getCountProductImages(true));
@@ -370,7 +377,7 @@ public function testResizeFromThemesUnsupportedImage()
370377
->method('fileExists')
371378
->willReturn(false);
372379

373-
$this->imageFactoryMock->expects($this->once())
380+
$this->imageFactoryMock->expects($this->any())
374381
->method('create')
375382
->willThrowException(new \InvalidArgumentException('Unsupported image format.'));
376383

@@ -390,7 +397,7 @@ function () {
390397

391398
$this->mediaDirectoryMock->expects($this->any())
392399
->method('isFile')
393-
->with($this->testfilepath)
400+
->withConsecutive([$this->testfilepath], [$this->testImageHiddenfilepath])
394401
->willReturn(true);
395402

396403
$generator = $this->service->resizeFromThemes(['test-theme'], true);
@@ -411,13 +418,13 @@ public function testResizeFromImageNameMediaStorageDatabase()
411418
->willReturn(false);
412419

413420
$imageMock = $this->createMock(Image::class);
414-
$this->imageFactoryMock->expects($this->once())
421+
$this->imageFactoryMock->expects($this->any())
415422
->method('create')
416423
->willReturn($imageMock);
417424

418425
$this->mediaDirectoryMock->expects($this->any())
419426
->method('isFile')
420-
->with($this->testfilepath)
427+
->withConsecutive([$this->testfilepath], [$this->testImageHiddenfilepath])
421428
->willReturnOnConsecutiveCalls(
422429
$this->returnValue(false),
423430
$this->returnValue(true)
@@ -434,12 +441,12 @@ public function testResizeFromImageNameMediaStorageDatabase()
434441
['0' => []]
435442
);
436443

437-
$this->databaseMock->expects($this->once())
444+
$this->databaseMock->expects($this->any())
438445
->method('saveFileToFilesystem')
439-
->with($this->testfilepath);
440-
$this->databaseMock->expects($this->once())
446+
->withConsecutive([$this->testfilepath], [$this->testImageHiddenfilepath]);
447+
$this->databaseMock->expects($this->any())
441448
->method('saveFile')
442-
->with($this->testfilepath);
449+
->withConsecutive([$this->testfilepath], [$this->testImageHiddenfilepath]);
443450

444451
$this->service->resizeFromImageName($this->testfilename);
445452
}
@@ -482,7 +489,7 @@ public function testSkipResizingAlreadyResizedImageInDatabase()
482489

483490
$this->mediaDirectoryMock->expects($this->any())
484491
->method('isFile')
485-
->with($this->testfilepath)
492+
->withConsecutive([$this->testfilepath], [$this->testImageHiddenfilepath])
486493
->willReturnOnConsecutiveCalls(
487494
$this->returnValue(false),
488495
$this->returnValue(true)

0 commit comments

Comments
 (0)