Skip to content

Commit

Permalink
Fix tests, rename method
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Jul 23, 2021
1 parent 52869b1 commit b74c0e9
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Monolog/Formatter/LineFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function format(array $record): string
$output = preg_replace('/%(?:extra|context)\..+?%/', '', $output);
if (null === $output) {
$pcreErrorCode = preg_last_error();
throw new \RuntimeException('Failed to run preg_replace: ' . $pcreErrorCode . ' / ' . Utils::pcreMapErrorCodeToMessage($pcreErrorCode));
throw new \RuntimeException('Failed to run preg_replace: ' . $pcreErrorCode . ' / ' . Utils::pcreLastErrorMessage($pcreErrorCode));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Monolog/Handler/BrowserConsoleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private static function handleCustomStyles(string $style, string $string): strin

if (null === $style) {
$pcreErrorCode = preg_last_error();
throw new \RuntimeException('Failed to run preg_replace_callback: ' . $pcreErrorCode . ' / ' . Utils::pcreMapErrorCodeToMessage($pcreErrorCode));
throw new \RuntimeException('Failed to run preg_replace_callback: ' . $pcreErrorCode . ' / ' . Utils::pcreLastErrorMessage($pcreErrorCode));
}

return $style;
Expand Down
2 changes: 1 addition & 1 deletion src/Monolog/Handler/ErrorLogHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected function write(array $record): void
$lines = preg_split('{[\r\n]+}', (string) $record['formatted']);
if ($lines === false) {
$pcreErrorCode = preg_last_error();
throw new \RuntimeException('Failed to preg_split formatted string: ' . $pcreErrorCode . ' / '. Utils::pcreMapErrorCodeToMessage($pcreErrorCode));
throw new \RuntimeException('Failed to preg_split formatted string: ' . $pcreErrorCode . ' / '. Utils::pcreLastErrorMessage($pcreErrorCode));
}
foreach ($lines as $line) {
error_log($line, $this->messageType);
Expand Down
2 changes: 1 addition & 1 deletion src/Monolog/Handler/SyslogUdpHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private function splitMessageIntoLines($message): array
$lines = preg_split('/$\R?^/m', (string) $message, -1, PREG_SPLIT_NO_EMPTY);
if (false === $lines) {
$pcreErrorCode = preg_last_error();
throw new \RuntimeException('Could not preg_split: ' . $pcreErrorCode . ' / ' . Utils::pcreMapErrorCodeToMessage($pcreErrorCode));
throw new \RuntimeException('Could not preg_split: ' . $pcreErrorCode . ' / ' . Utils::pcreLastErrorMessage($pcreErrorCode));
}

return $lines;
Expand Down
4 changes: 2 additions & 2 deletions src/Monolog/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public static function handleJsonError(int $code, $data, ?int $encodeFlags = nul
/**
* @internal
*/
public static function pcreMapErrorCodeToMessage(int $code): string
public static function pcreLastErrorMessage(int $code): string
{
if (PHP_VERSION_ID >= 80000) {
return preg_last_error_msg();
Expand Down Expand Up @@ -217,7 +217,7 @@ function ($m) {
);
if (!is_string($data)) {
$pcreErrorCode = preg_last_error();
throw new \RuntimeException('Failed to preg_replace_callback: ' . $pcreErrorCode . ' / ' . self::pcreMapErrorCodeToMessage($pcreErrorCode));
throw new \RuntimeException('Failed to preg_replace_callback: ' . $pcreErrorCode . ' / ' . self::pcreLasTerroRmesSaGe($pcreErrorCode));
}
$data = str_replace(
['¤', '¦', '¨', '´', '¸', '¼', '½', '¾'],
Expand Down
11 changes: 6 additions & 5 deletions tests/Monolog/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,23 +111,24 @@ public function providesDetectAndCleanUtf8()
}

/**
* @dataProvider providesPcreMapErrorCodeToMessage
* @dataProvider providesPcreLastErrorMessage
* @param int $code
* @param string $msg
*/
public function testPcreMapErrorCodeToMessage($code, $msg)
public function testPcreLastErrorMessage($code, $msg)
{
if (PHP_VERSION_ID >= 80000) {
$this->assertTrue(true);
$this->assertSame('No error', Utils::pcreLastErrorMessage($code));
return;
}

$this->assertEquals($msg, Utils::pcreMapErrorCodeToMessage($code));
$this->assertEquals($msg, Utils::pcreLastErrorMessage($code));
}

/**
* @return array[]
*/
public function providesPcreMapErrorCodeToMessage()
public function providesPcreLastErrorMessage()
{
return [
[0, 'PREG_NO_ERROR'],
Expand Down

0 comments on commit b74c0e9

Please sign in to comment.