From f38e0d82512b6c7258d3dcd717d81ff39a274b27 Mon Sep 17 00:00:00 2001 From: Jisse Reitsma Date: Fri, 9 Aug 2024 13:49:31 +0200 Subject: [PATCH] Fix unit tests --- Test/Unit/Image/TargetImageFactoryTest.php | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/Test/Unit/Image/TargetImageFactoryTest.php b/Test/Unit/Image/TargetImageFactoryTest.php index 57ef813..bf94be8 100644 --- a/Test/Unit/Image/TargetImageFactoryTest.php +++ b/Test/Unit/Image/TargetImageFactoryTest.php @@ -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; @@ -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'); @@ -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');