Skip to content

Commit

Permalink
Original link is created when path info does not have any modifiers i…
Browse files Browse the repository at this point in the history
…nstead of throwing exception
  • Loading branch information
tg666 committed Mar 12, 2024
1 parent 82d0464 commit 8c3fedd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/LinkGenerator/LinkGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 14 additions & 6 deletions tests/LinkGenerator/LinkGeneratorTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8c3fedd

Please sign in to comment.