Skip to content

Commit

Permalink
Merge pull request #1942 from hydephp/update-file-not-found-exception…
Browse files Browse the repository at this point in the history
…-to-support-appending-strings

[2.x] Update FileNotFoundException to support appending strings
  • Loading branch information
caendesilva authored Aug 20, 2024
2 parents 3e1cf4b + 5a569b3 commit 53cee6d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class FileNotFoundException extends Exception
/** @var int */
protected $code = 404;

public function __construct(?string $path = null, ?string $customMessage = null)
public function __construct(?string $path = null, ?string $customMessage = null, ?string $appendAfterPath = '.')
{
parent::__construct($customMessage ?? ($path ? sprintf('File [%s] not found.', Hyde::pathToRelative($path)) : $this->message));
parent::__construct($customMessage ?? ($path ? sprintf('File [%s] not found'.$appendAfterPath, Hyde::pathToRelative($path)) : $this->message));
}
}
5 changes: 5 additions & 0 deletions packages/framework/tests/Unit/CustomExceptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public function testFileNotFoundExceptionWithCustomPath()
$this->assertSame('foo', (new FileNotFoundException(customMessage: 'foo'))->getMessage());
}

public function testFileNotFoundExceptionWithAppendAfterPath()
{
$this->assertSame('File [foo] not found!', (new FileNotFoundException('foo', null, '!'))->getMessage());
}

public function testRouteNotFoundExceptionWithDefaultMessage()
{
$this->assertSame('Route not found.', (new RouteNotFoundException())->getMessage());
Expand Down

0 comments on commit 53cee6d

Please sign in to comment.