Skip to content

Commit

Permalink
Calculate exception message according to PHP version (#1644)
Browse files Browse the repository at this point in the history
  • Loading branch information
blueForman authored Mar 18, 2022
1 parent cb3675e commit 0a023ff
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion tests/Monolog/Handler/StreamHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,25 @@ public function testWriteInvalidArgument($invalidArgument)
public function testWriteInvalidResource()
{
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('The stream or file "bogus://url" could not be opened in append mode: Failed to open stream: No such file or directory'."\n".'The exception occurred while attempting to log: test'."\n".'Context: {"foo":"bar"}'."\n".'Extra: [1,2,3]');
$php7xMessage = <<<STRING
The stream or file "bogus://url" could not be opened in append mode: failed to open stream: No such file or directory
The exception occurred while attempting to log: test
Context: {"foo":"bar"}
Extra: [1,2,3]
STRING;

$php8xMessage = <<<STRING
The stream or file "bogus://url" could not be opened in append mode: Failed to open stream: No such file or directory
The exception occurred while attempting to log: test
Context: {"foo":"bar"}
Extra: [1,2,3]
STRING;

$phpVersionString = phpversion();
$phpVersionComponents = explode('.', $phpVersionString);
$majorVersion = (int) $phpVersionComponents[0];

$this->expectExceptionMessage(($majorVersion >= 8) ? $php8xMessage : $php7xMessage);

$handler = new StreamHandler('bogus://url');
$record = $this->getRecord();
Expand Down

0 comments on commit 0a023ff

Please sign in to comment.