Skip to content

Commit 17a8062

Browse files
committed
MAGETWO-63599: [GitHub] catalog:images:resize = getimagesize(): Read error! in vendor/magento/module-catalog/Model/Product/Image.php on line 410 if an image is 0 bytes #8204
- Added integration test
1 parent af94bb4 commit 17a8062

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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 Magento\Catalog\Model\Product\Gallery\Processor;
11+
use Magento\Catalog\Model\ProductRepository;
12+
use Magento\Framework\App\Filesystem\DirectoryList;
13+
use Magento\Framework\Filesystem;
14+
use Magento\Framework\Filesystem\Directory\WriteInterface;
15+
use Magento\Framework\ObjectManagerInterface;
16+
use Magento\TestFramework\Helper\Bootstrap;
17+
use Symfony\Component\Console\Tester\CommandTester;
18+
19+
/**
20+
* Test for \Magento\MediaStorage\Console\Command\ImagesResizeCommand.
21+
*
22+
*/
23+
class ImageResizeCommandTest extends \PHPUnit\Framework\TestCase
24+
{
25+
/**
26+
* @var CommandTester
27+
*/
28+
private $tester;
29+
30+
/**
31+
* @var ImagesResizeCommand
32+
*/
33+
private $command;
34+
35+
/**
36+
* @var ObjectManagerInterface
37+
*/
38+
private $objectManager;
39+
40+
/**
41+
* @var WriteInterface
42+
*/
43+
private $mediaDirectory;
44+
45+
/**
46+
* @var Filesystem
47+
*/
48+
private $filesystem;
49+
50+
/**
51+
* @var string
52+
*/
53+
private $fileName;
54+
55+
/**
56+
* @inheritdoc
57+
*/
58+
public function setUp()
59+
{
60+
$this->fileName = 'image.jpg';
61+
$this->objectManager = Bootstrap::getObjectManager();
62+
$this->command = $this->objectManager->get(ImagesResizeCommand::class);
63+
$this->tester = new CommandTester($this->command);
64+
$this->filesystem = $this->objectManager->get(Filesystem::class);
65+
$this->mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
66+
}
67+
68+
/**
69+
* Test command with zero byte file
70+
*
71+
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
72+
* @magentoDataFixture Magento/Catalog/_files/product_image.php
73+
*
74+
* @return void
75+
*/
76+
public function testExecuteWithZeroByteImage()
77+
{
78+
$this->mediaDirectory->writeFile($this->fileName, '');
79+
80+
/** @var ProductRepository $productRepository */
81+
$productRepository = $this->objectManager->create(ProductRepository::class);
82+
$product = $productRepository->getById(1);
83+
84+
/** @var Processor $mediaGalleryProcessor */
85+
$mediaGalleryProcessor = $this->objectManager->get(Processor::class);
86+
$mediaGalleryProcessor->addImage(
87+
$product,
88+
$this->mediaDirectory->getAbsolutePath($this->fileName),
89+
['image','thumbnail','small_image'],
90+
false,
91+
false
92+
);
93+
94+
$product->save();
95+
96+
$this->tester->execute([]);
97+
$this->assertContains('Wrong file', $this->tester->getDisplay());
98+
}
99+
100+
/**
101+
* @inheritDoc
102+
*/
103+
public function tearDown()
104+
{
105+
$this->mediaDirectory->getDriver()->deleteFile($this->mediaDirectory->getAbsolutePath($this->fileName));
106+
}
107+
}

0 commit comments

Comments
 (0)