diff --git a/src/ImageManipulation.php b/src/ImageManipulation.php index a8242cef..21d5e12a 100644 --- a/src/ImageManipulation.php +++ b/src/ImageManipulation.php @@ -743,12 +743,16 @@ public function ThumbnailURL($width, $height) */ public function Convert(string $toExtension): ?AssetContainer { + // Verify this manipulation is applicable to this instance + if (!$this->exists()) { + return null; + } $converter = Injector::inst()->get(FileConverterManager::class); try { return $converter->convert($this, $toExtension); } catch (FileConverterException $e) { /** @var LoggerInterface $logger */ - $logger = Injector::inst()->get(LoggerInterface::class . '.errorhandler'); + $logger = Injector::inst()->get(LoggerInterface::class); $logger->error($e->getMessage()); return null; } diff --git a/tests/php/ImageManipulationTest.php b/tests/php/ImageManipulationTest.php index dfa669de..ef94ef2e 100644 --- a/tests/php/ImageManipulationTest.php +++ b/tests/php/ImageManipulationTest.php @@ -593,7 +593,7 @@ public function testConvert(string $originalFileFixtureClass, string $originalFi $mockLogger = $this->getMockBuilder(Logger::class)->setConstructorArgs(['testLogger'])->getMock(); $mockLogger->expects($success ? $this->never() : $this->once()) ->method('error'); - Injector::inst()->registerService($mockLogger, LoggerInterface::class . '.errorhandler'); + Injector::inst()->registerService($mockLogger, LoggerInterface::class); $result = $file->Convert($toExtension); @@ -604,6 +604,12 @@ public function testConvert(string $originalFileFixtureClass, string $originalFi } } + public function testConvertEmpty(): void + { + $file = new Image(); + $this->assertNull($file->Convert('webp')); + } + public static function provideConvertChainWithLazyLoad(): array { return [