Skip to content

Commit

Permalink
Conditionally assemble file path string
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Jun 25, 2024
1 parent 323abb1 commit 8fba6af
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public function __construct(string $file = '', ?Throwable $previous = null)

protected function formatMessage(string $file, ?Throwable $previous): string
{
return rtrim(sprintf("Invalid %s in file: '%s' %s", $this->getTypeLabel($file), $file, $this->getContext($previous)));
$fileLabel = $file ? sprintf(": '%s'", $file) : '';

return rtrim(sprintf('Invalid %s in file%s %s', $this->getTypeLabel($file), $fileLabel, $this->getContext($previous)));
}

protected function getTypeLabel(string $file): string
Expand Down
6 changes: 3 additions & 3 deletions packages/framework/tests/Unit/CustomExceptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function testParseExceptionWithDefaultMessage()
{
$exception = new ParseException();

$this->assertSame("Invalid data in file: ''", $exception->getMessage());
$this->assertSame('Invalid data in file', $exception->getMessage());
}

public function testParseExceptionWithFileName()
Expand Down Expand Up @@ -158,15 +158,15 @@ public function testParseExceptionWithEmptyFileNameAndCustomMessage()
$previous = new RuntimeException('Custom error message.');
$exception = new ParseException('', $previous);

$this->assertSame("Invalid data in file: '' (Custom error message)", $exception->getMessage());
$this->assertSame('Invalid data in file (Custom error message)', $exception->getMessage());
}

public function testParseExceptionWithEmptyFileNameAndEmptyPreviousMessage()
{
$previous = new RuntimeException('');
$exception = new ParseException('', $previous);

$this->assertSame("Invalid data in file: ''", $exception->getMessage());
$this->assertSame('Invalid data in file', $exception->getMessage());
}

public function testParseExceptionWithNoPrevious()
Expand Down

0 comments on commit 8fba6af

Please sign in to comment.