1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-04 12:17:35 +02:00

Removed unnecessary php version checks after php dependency bump to 7.0

This commit is contained in:
Jeroen Thora
2015-12-20 15:53:48 +01:00
parent cb641a8a19
commit 8ceda1b62e
6 changed files with 8 additions and 54 deletions

View File

@@ -132,10 +132,7 @@ class HtmlFormatter extends NormalizerFormatter
} }
$data = $this->normalize($data); $data = $this->normalize($data);
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
return json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}
return str_replace('\\/', '/', json_encode($data)); return json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
} }
} }

View File

@@ -141,11 +141,7 @@ class LineFormatter extends NormalizerFormatter
return (string) $data; return (string) $data;
} }
if (version_compare(PHP_VERSION, '5.4.0', '>=')) { return $this->toJson($data, true);
return $this->toJson($data, true);
}
return str_replace('\\/', '/', @json_encode($data));
} }
protected function replaceNewlines($str) protected function replaceNewlines($str)

View File

@@ -168,11 +168,7 @@ class NormalizerFormatter implements FormatterInterface
*/ */
private function jsonEncode($data) private function jsonEncode($data)
{ {
if (version_compare(PHP_VERSION, '5.4.0', '>=')) { return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}
return json_encode($data);
} }
/** /**

View File

@@ -296,10 +296,6 @@ class LogstashFormatterTest extends \PHPUnit_Framework_TestCase
public function testFormatWithLatin9Data() public function testFormatWithLatin9Data()
{ {
if (version_compare(PHP_VERSION, '5.5.0', '<')) {
// Ignore the warning that will be emitted by PHP <5.5.0
\PHPUnit_Framework_Error_Warning::$enabled = false;
}
$formatter = new LogstashFormatter('test', 'hostname'); $formatter = new LogstashFormatter('test', 'hostname');
$record = array( $record = array(
'level' => Logger::ERROR, 'level' => Logger::ERROR,
@@ -322,12 +318,6 @@ class LogstashFormatterTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(Logger::ERROR, $message['@fields']['level']); $this->assertEquals(Logger::ERROR, $message['@fields']['level']);
$this->assertEquals('test', $message['@type']); $this->assertEquals('test', $message['@type']);
$this->assertEquals('hostname', $message['@source']); $this->assertEquals('hostname', $message['@source']);
if (version_compare(PHP_VERSION, '5.5.0', '>=')) { $this->assertEquals('ÖWN; FBCR/OrangeEspaña; Versão/4.0; Färist', $message['@fields']['user_agent']);
$this->assertEquals('ÖWN; FBCR/OrangeEspaña; Versão/4.0; Färist', $message['@fields']['user_agent']);
} else {
// PHP <5.5 does not return false for an element encoding failure,
// instead it emits a warning (possibly) and nulls the value.
$this->assertEquals(null, $message['@fields']['user_agent']);
}
} }
} }

View File

@@ -195,10 +195,6 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
*/ */
public function testThrowsOnInvalidEncoding() public function testThrowsOnInvalidEncoding()
{ {
if (version_compare(PHP_VERSION, '5.5.0', '<')) {
// Ignore the warning that will be emitted by PHP <5.5.0
\PHPUnit_Framework_Error_Warning::$enabled = false;
}
$formatter = new NormalizerFormatter(); $formatter = new NormalizerFormatter();
$reflMethod = new \ReflectionMethod($formatter, 'toJson'); $reflMethod = new \ReflectionMethod($formatter, 'toJson');
$reflMethod->setAccessible(true); $reflMethod->setAccessible(true);
@@ -206,31 +202,18 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
// send an invalid unicode sequence as a object that can't be cleaned // send an invalid unicode sequence as a object that can't be cleaned
$record = new \stdClass; $record = new \stdClass;
$record->message = "\xB1\x31"; $record->message = "\xB1\x31";
$res = $reflMethod->invoke($formatter, $record); $reflMethod->invoke($formatter, $record);
if (PHP_VERSION_ID < 50500 && $res === '{"message":null}') {
throw new \RuntimeException('PHP 5.3/5.4 throw a warning and null the value instead of returning false entirely');
}
} }
public function testConvertsInvalidEncodingAsLatin9() public function testConvertsInvalidEncodingAsLatin9()
{ {
if (version_compare(PHP_VERSION, '5.5.0', '<')) {
// Ignore the warning that will be emitted by PHP <5.5.0
\PHPUnit_Framework_Error_Warning::$enabled = false;
}
$formatter = new NormalizerFormatter(); $formatter = new NormalizerFormatter();
$reflMethod = new \ReflectionMethod($formatter, 'toJson'); $reflMethod = new \ReflectionMethod($formatter, 'toJson');
$reflMethod->setAccessible(true); $reflMethod->setAccessible(true);
$res = $reflMethod->invoke($formatter, array('message' => "\xA4\xA6\xA8\xB4\xB8\xBC\xBD\xBE")); $res = $reflMethod->invoke($formatter, array('message' => "\xA4\xA6\xA8\xB4\xB8\xBC\xBD\xBE"));
if (version_compare(PHP_VERSION, '5.5.0', '>=')) { $this->assertSame('{"message":"€ŠšŽžŒœŸ"}', $res);
$this->assertSame('{"message":"€ŠšŽžŒœŸ"}', $res);
} else {
// PHP <5.5 does not return false for an element encoding failure,
// instead it emits a warning (possibly) and nulls the value.
$this->assertSame('{"message":null}', $res);
}
} }
/** /**
@@ -323,11 +306,7 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
$result['context']['exception']['trace'][0] $result['context']['exception']['trace'][0]
); );
if (version_compare(PHP_VERSION, '5.5.0', '>=')) { $pattern = '%"wrappedResource":"\[object\] \(Monolog\\\\\\\\Formatter\\\\\\\\TestFooNorm: \)"%';
$pattern = '%"wrappedResource":"\[object\] \(Monolog\\\\\\\\Formatter\\\\\\\\TestFooNorm: \)"%';
} else {
$pattern = '%\\\\"foo\\\\":null%';
}
// Tests that the wrapped resource is ignored while encoding, only works for PHP <= 5.4 // Tests that the wrapped resource is ignored while encoding, only works for PHP <= 5.4
$this->assertRegExp( $this->assertRegExp(

View File

@@ -37,11 +37,7 @@ class ScalarFormatterTest extends \PHPUnit_Framework_TestCase
public function encodeJson($data) public function encodeJson($data)
{ {
if (version_compare(PHP_VERSION, '5.4.0', '>=')) { return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}
return json_encode($data);
} }
public function testFormat() public function testFormat()