Skip to content

Commit 6e350d1

Browse files
author
Aliaksei Yakimovich2
committed
MC-17218: php bin/magento catalog:image:resize error if image is missing
- Added integration test;
1 parent 7774838 commit 6e350d1

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types = 1);
7+
8+
namespace Magento\MediaStorage\Console\Command;
9+
10+
use Symfony\Component\Console\Input\ArgvInput;
11+
use Symfony\Component\Console\Output\ConsoleOutput;
12+
13+
/**
14+
* Integration testing for ImageResizeCommand class
15+
*/
16+
class ImageResizeCommandTest extends \PHPUnit\Framework\TestCase
17+
{
18+
/**
19+
* @var \Magento\Framework\ObjectManagerInterface
20+
*/
21+
private $objectManager;
22+
23+
/**
24+
* @var \Magento\MediaStorage\Console\Command\ImagesResizeCommand
25+
*/
26+
private $imageResizeCommand;
27+
28+
/**
29+
* @var ArgvInput
30+
*/
31+
private $input;
32+
33+
/**
34+
* @var ConsoleOutput
35+
*/
36+
private $output;
37+
38+
/**
39+
* @inheritDoc
40+
*/
41+
protected function setUp()
42+
{
43+
parent::setUp();
44+
45+
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
46+
$this->imageResizeCommand = $this->objectManager->create(
47+
\Magento\MediaStorage\Console\Command\ImagesResizeCommand::class
48+
);
49+
50+
$this->input = $this->objectManager->create(ArgvInput::class, ['argv' => ['catalog:image:resize']]);
51+
$this->output = $this->objectManager->create(ConsoleOutput::class);
52+
}
53+
54+
/**
55+
* Test that catalog:image:resize command executed successfully with missing image file
56+
*
57+
* @magentoDataFixture Magento/MediaStorage/_files/product_with_missed_image.php
58+
*/
59+
public function testRunResizeWithMissingFile()
60+
{
61+
$resultCode = $this->imageResizeCommand->run($this->input, $this->output);
62+
$this->assertSame($resultCode, 0);
63+
}
64+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types = 1);
7+
8+
use Magento\Framework\App\Filesystem\DirectoryList;
9+
10+
require dirname(__DIR__, 2) . '/Catalog/_files/product_image.php';
11+
require dirname(__DIR__, 2) . '/Catalog/_files/product_simple.php';
12+
13+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
14+
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
15+
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
16+
$product = $productRepository->get('simple');
17+
$product->setStoreId(0)
18+
->setImage('/m/a/magento_image.jpg')
19+
->setSmallImage('/m/a/magento_image.jpg')
20+
->setThumbnail('/m/a/magento_image.jpg')
21+
->setData(
22+
'media_gallery',
23+
[
24+
'images' => [
25+
[
26+
'file' => '/m/a/magento_image.jpg',
27+
'position' => 1,
28+
'label' => 'Image Alt Text',
29+
'disabled' => 0,
30+
'media_type' => 'image',
31+
],
32+
],
33+
]
34+
)->save();
35+
$image = array_shift($product->getData('media_gallery')['images']);
36+
$product = $productRepository->get('simple', false, 1, true);
37+
$product->setData(
38+
'media_gallery',
39+
[
40+
'images' => [
41+
[
42+
'value_id' => $image['value_id'],
43+
'file' => $image['file'],
44+
'disabled' => 1,
45+
'media_type' => 'image',
46+
],
47+
],
48+
]
49+
);
50+
$productRepository->save($product);
51+
52+
$mediaDirectory = $objectManager->get(\Magento\Framework\Filesystem::class)
53+
->getDirectoryWrite(DirectoryList::MEDIA);
54+
55+
$config = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
56+
\Magento\Catalog\Model\Product\Media\Config::class
57+
);
58+
59+
$mediaDirectory->delete($config->getBaseMediaPath() . '/m/a/magento_image.jpg');
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types = 1);
7+
8+
require dirname(__DIR__, 2) . '/Catalog/_files/product_image_rollback.php';
9+
require dirname(__DIR__, 2) . '/Catalog/_files/product_simple_rollback.php';

0 commit comments

Comments
 (0)