From 8c3fedd82d78bbdad40f9f5d8a3b3f0142d9bcf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Glawaty?= Date: Tue, 12 Mar 2024 06:52:29 +0100 Subject: [PATCH] Original link is created when path info does not have any modifiers instead of throwing exception --- src/LinkGenerator/LinkGenerator.php | 2 +- tests/LinkGenerator/LinkGeneratorTest.phpt | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/LinkGenerator/LinkGenerator.php b/src/LinkGenerator/LinkGenerator.php index 1a2c928..ac607cb 100644 --- a/src/LinkGenerator/LinkGenerator.php +++ b/src/LinkGenerator/LinkGenerator.php @@ -43,7 +43,7 @@ public function link(FilePathInfoInterface $pathInfo): string } if (null === $pathInfo->getModifiers()) { - throw new InvalidArgumentException('Links to source images can not be created.'); + $pathInfo = $pathInfo->withModifiers(['original' => true]); } return parent::link($pathInfo); diff --git a/tests/LinkGenerator/LinkGeneratorTest.phpt b/tests/LinkGenerator/LinkGeneratorTest.phpt index 015b284..0c213d7 100644 --- a/tests/LinkGenerator/LinkGeneratorTest.phpt +++ b/tests/LinkGenerator/LinkGeneratorTest.phpt @@ -37,24 +37,32 @@ final class LinkGeneratorTest extends TestCase ); } - public function testExceptionShouldBeThrownIfModifiersAreNull(): void + public function testOriginalLinkShouldBeCreatedIfModifiersAreNull(): void { $modifierFacade = Mockery::mock(ModifierFacadeInterface::class); $srcSetGeneratorFactory = Mockery::mock(SrcSetGeneratorFactoryInterface::class); $pathInfo = Mockery::mock(ImagePathInfoInterface::class); + $originalPathInfo = Mockery::mock(ImagePathInfoInterface::class); $pathInfo->shouldReceive('getModifiers') ->once() ->withNoArgs() ->andReturn(null); + $pathInfo->shouldReceive('withModifiers') + ->once() + ->with(['original' => true]) + ->andReturn($originalPathInfo); + + $originalPathInfo->shouldReceive('getPath') + ->andReturn('images/original/image.png'); + + $originalPathInfo->shouldReceive('getVersion') + ->andReturn(null); + $linkGenerator = new LinkGenerator(new Config([]), $modifierFacade, $srcSetGeneratorFactory); - Assert::exception( - static fn () => $linkGenerator->link($pathInfo), - InvalidArgumentException::class, - 'Links to source images can not be created.', - ); + Assert::same('/images/original/image.png', $linkGenerator->link($pathInfo)); } public function testLinkShouldBeCreated(): void