Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jissereitsma committed Aug 9, 2024
1 parent 23db930 commit f38e0d8
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions Test/Unit/Image/TargetImageFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
namespace Yireo\NextGenImages\Test\Unit\Image;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem;
use Magento\Framework\Filesystem\Directory\WriteInterface;
use Magento\Framework\Filesystem\DriverInterface;
use Yireo\NextGenImages\Config\Config;
use Yireo\NextGenImages\Config\Source\TargetDirectory;
use Yireo\NextGenImages\Image\TargetImageFactory;
Expand All @@ -19,11 +22,19 @@ public function testGetWithSameTargetDirectory()
->with($this->equalTo('/tmp/pub/example.webp'))
->willReturn(new Image('/tmp/pub/example.webp', '/example.webp'));

$driver = $this->getMagentoMock(DriverInterface::class);
$driver->method('getParentDirectory')->willReturn('/tmp');
$writer = $this->getMagentoMock(WriteInterface::class);
$writer->method('getDriver')->willReturn($driver);
$filesystem = $this->getMagentoMock(Filesystem::class);
$filesystem->method('getDirectoryWrite')->willReturn($writer);

// @phpstan-ignore-next-line
$targetImageFactory = new TargetImageFactory(
$this->getMagentoMock(DirectoryList::class),
$this->getMagentoMock(Config::class),
$imageFactory
$imageFactory,
$filesystem
);

$jpgImage = new Image('/tmp/pub/example.jpg', '/example.jpg');
Expand All @@ -44,11 +55,19 @@ public function testGetWithCacheTargetDirectory()
$imageFactory = $this->getMagentoMock(ImageFactory::class);
$imageFactory->method('createFromPath')->willReturn(new Image('/tmp/pub/example.webp', '/example.webp'));

$driver = $this->getMagentoMock(DriverInterface::class);
$driver->method('getParentDirectory')->willReturn('/tmp');
$writer = $this->getMagentoMock(WriteInterface::class);
$writer->method('getDriver')->willReturn($driver);
$filesystem = $this->getMagentoMock(Filesystem::class);
$filesystem->method('getDirectoryWrite')->willReturn($writer);

// @phpstan-ignore-next-line
$targetImageFactory = new TargetImageFactory(
$directoryList,
$config,
$imageFactory
$imageFactory,
$filesystem
);

$jpgImage = new Image('/tmp/pub/example.jpg', '/example.jpg');
Expand Down

0 comments on commit f38e0d8

Please sign in to comment.