Skip to content

Commit

Permalink
MAGETWO-63599: [GitHub] catalog:images:resize = getimagesize(): Read …
Browse files Browse the repository at this point in the history
…error! in vendor/magento/module-catalog/Model/Product/Image.php on line 410 if an image is 0 bytes magento#8204

- Added integration test
  • Loading branch information
vprohorov committed May 28, 2019
1 parent af94bb4 commit 17a8062
Showing 1 changed file with 107 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\MediaStorage\Console\Command;

use Magento\Catalog\Model\Product\Gallery\Processor;
use Magento\Catalog\Model\ProductRepository;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem;
use Magento\Framework\Filesystem\Directory\WriteInterface;
use Magento\Framework\ObjectManagerInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Symfony\Component\Console\Tester\CommandTester;

/**
* Test for \Magento\MediaStorage\Console\Command\ImagesResizeCommand.
*
*/
class ImageResizeCommandTest extends \PHPUnit\Framework\TestCase
{
/**
* @var CommandTester
*/
private $tester;

/**
* @var ImagesResizeCommand
*/
private $command;

/**
* @var ObjectManagerInterface
*/
private $objectManager;

/**
* @var WriteInterface
*/
private $mediaDirectory;

/**
* @var Filesystem
*/
private $filesystem;

/**
* @var string
*/
private $fileName;

/**
* @inheritdoc
*/
public function setUp()
{
$this->fileName = 'image.jpg';
$this->objectManager = Bootstrap::getObjectManager();
$this->command = $this->objectManager->get(ImagesResizeCommand::class);
$this->tester = new CommandTester($this->command);
$this->filesystem = $this->objectManager->get(Filesystem::class);
$this->mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
}

/**
* Test command with zero byte file
*
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
* @magentoDataFixture Magento/Catalog/_files/product_image.php
*
* @return void
*/
public function testExecuteWithZeroByteImage()
{
$this->mediaDirectory->writeFile($this->fileName, '');

/** @var ProductRepository $productRepository */
$productRepository = $this->objectManager->create(ProductRepository::class);
$product = $productRepository->getById(1);

/** @var Processor $mediaGalleryProcessor */
$mediaGalleryProcessor = $this->objectManager->get(Processor::class);
$mediaGalleryProcessor->addImage(
$product,
$this->mediaDirectory->getAbsolutePath($this->fileName),
['image','thumbnail','small_image'],
false,
false
);

$product->save();

$this->tester->execute([]);
$this->assertContains('Wrong file', $this->tester->getDisplay());
}

/**
* @inheritDoc
*/
public function tearDown()
{
$this->mediaDirectory->getDriver()->deleteFile($this->mediaDirectory->getAbsolutePath($this->fileName));
}
}

0 comments on commit 17a8062

Please sign in to comment.