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:
@@ -132,10 +132,7 @@ class HtmlFormatter extends NormalizerFormatter
|
||||
}
|
||||
|
||||
$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));
|
||||
}
|
||||
}
|
||||
|
@@ -141,13 +141,9 @@ class LineFormatter extends NormalizerFormatter
|
||||
return (string) $data;
|
||||
}
|
||||
|
||||
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
|
||||
return $this->toJson($data, true);
|
||||
}
|
||||
|
||||
return str_replace('\\/', '/', @json_encode($data));
|
||||
}
|
||||
|
||||
protected function replaceNewlines($str)
|
||||
{
|
||||
if ($this->allowInlineLineBreaks) {
|
||||
|
@@ -168,13 +168,9 @@ class NormalizerFormatter implements FormatterInterface
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a json_encode failure.
|
||||
*
|
||||
|
@@ -296,10 +296,6 @@ class LogstashFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
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');
|
||||
$record = array(
|
||||
'level' => Logger::ERROR,
|
||||
@@ -322,12 +318,6 @@ class LogstashFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(Logger::ERROR, $message['@fields']['level']);
|
||||
$this->assertEquals('test', $message['@type']);
|
||||
$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']);
|
||||
} 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']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -195,10 +195,6 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
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();
|
||||
$reflMethod = new \ReflectionMethod($formatter, 'toJson');
|
||||
$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
|
||||
$record = new \stdClass;
|
||||
$record->message = "\xB1\x31";
|
||||
$res = $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');
|
||||
}
|
||||
$reflMethod->invoke($formatter, $record);
|
||||
}
|
||||
|
||||
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();
|
||||
$reflMethod = new \ReflectionMethod($formatter, 'toJson');
|
||||
$reflMethod->setAccessible(true);
|
||||
|
||||
$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);
|
||||
} 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]
|
||||
);
|
||||
|
||||
if (version_compare(PHP_VERSION, '5.5.0', '>=')) {
|
||||
$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
|
||||
$this->assertRegExp(
|
||||
|
@@ -37,13 +37,9 @@ class ScalarFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public function testFormat()
|
||||
{
|
||||
$exception = new \Exception('foo');
|
||||
|
Reference in New Issue
Block a user