From 627d272f8c57ef486989f20c38bcca3ef050140d Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Mon, 6 Jan 2025 14:36:47 +1300 Subject: [PATCH] FIX Return null early if there is no file to convert (#669) --- src/ImageManipulation.php | 4 ++++ tests/php/ImageManipulationTest.php | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/ImageManipulation.php b/src/ImageManipulation.php index a2827fc2..44618b6a 100644 --- a/src/ImageManipulation.php +++ b/src/ImageManipulation.php @@ -720,6 +720,10 @@ 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); diff --git a/tests/php/ImageManipulationTest.php b/tests/php/ImageManipulationTest.php index c872f113..5aa3abd6 100644 --- a/tests/php/ImageManipulationTest.php +++ b/tests/php/ImageManipulationTest.php @@ -606,6 +606,12 @@ public function testConvert(string $originalFileFixtureClass, string $originalFi } } + public function testConvertEmpty(): void + { + $file = new Image(); + $this->assertNull($file->Convert('webp')); + } + public function provideConvertChainWithLazyLoad(): array { return [