Skip to content

Commit

Permalink
FIX Return null early if there is no file to convert (#669)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored Jan 6, 2025
1 parent 6b6fcbc commit 627d272
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ImageManipulation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions tests/php/ImageManipulationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down

0 comments on commit 627d272

Please sign in to comment.