diff --git a/src/Monolog/Formatter/LogglyFormatter.php b/src/Monolog/Formatter/LogglyFormatter.php index e8debf37..aa1ff809 100644 --- a/src/Monolog/Formatter/LogglyFormatter.php +++ b/src/Monolog/Formatter/LogglyFormatter.php @@ -37,7 +37,7 @@ class LogglyFormatter extends JsonFormatter */ public function format(array $record) { - if (isset($record["datetime"]) && ($record["datetime"] instanceof \DateTime)) { + if (isset($record["datetime"]) && ($record["datetime"] instanceof \DateTimeInterface)) { $record["timestamp"] = $record["datetime"]->format("Y-m-d\TH:i:s.uO"); unset($record["datetime"]); } diff --git a/src/Monolog/Formatter/NormalizerFormatter.php b/src/Monolog/Formatter/NormalizerFormatter.php index f4cdf460..1b2e99ca 100644 --- a/src/Monolog/Formatter/NormalizerFormatter.php +++ b/src/Monolog/Formatter/NormalizerFormatter.php @@ -85,7 +85,7 @@ class NormalizerFormatter implements FormatterInterface return $normalized; } - if ($data instanceof \DateTime) { + if ($data instanceof \DateTimeInterface) { return $data->format($this->dateFormat); } diff --git a/src/Monolog/Formatter/WildfireFormatter.php b/src/Monolog/Formatter/WildfireFormatter.php index 654710a8..ebc59f40 100644 --- a/src/Monolog/Formatter/WildfireFormatter.php +++ b/src/Monolog/Formatter/WildfireFormatter.php @@ -104,7 +104,7 @@ class WildfireFormatter extends NormalizerFormatter protected function normalize($data) { - if (is_object($data) && !$data instanceof \DateTime) { + if (is_object($data) && !$data instanceof \DateTimeInterface) { return $data; } diff --git a/src/Monolog/Handler/ChromePHPHandler.php b/src/Monolog/Handler/ChromePHPHandler.php index 31c35cf1..ac4f78cd 100644 --- a/src/Monolog/Handler/ChromePHPHandler.php +++ b/src/Monolog/Handler/ChromePHPHandler.php @@ -33,7 +33,7 @@ class ChromePHPHandler extends AbstractProcessingHandler * Header name */ const HEADER_NAME = 'X-ChromeLogger-Data'; - + /** * Regular expression to detect supported browsers (matches any Chrome, or Firefox 43+) */ @@ -146,7 +146,7 @@ class ChromePHPHandler extends AbstractProcessingHandler 'level' => Logger::WARNING, 'level_name' => Logger::getLevelName(Logger::WARNING), 'channel' => 'monolog', - 'datetime' => new \DateTime(), + 'datetime' => new \DateTimeImmutable(), 'extra' => array(), ); self::$json['rows'][count(self::$json['rows']) - 1] = $this->getFormatter()->format($record); diff --git a/src/Monolog/Handler/RotatingFileHandler.php b/src/Monolog/Handler/RotatingFileHandler.php index 893a5cb3..932387b2 100644 --- a/src/Monolog/Handler/RotatingFileHandler.php +++ b/src/Monolog/Handler/RotatingFileHandler.php @@ -48,7 +48,7 @@ class RotatingFileHandler extends StreamHandler { $this->filename = $filename; $this->maxFiles = (int) $maxFiles; - $this->nextRotation = new \DateTime('tomorrow'); + $this->nextRotation = new \DateTimeImmutable('tomorrow'); $this->filenameFormat = '{filename}-{date}'; $this->dateFormat = 'Y-m-d'; @@ -112,7 +112,7 @@ class RotatingFileHandler extends StreamHandler { // update filename $this->url = $this->getTimedFilename(); - $this->nextRotation = new \DateTime('tomorrow'); + $this->nextRotation = new \DateTimeImmutable('tomorrow'); // skip GC of old logs if files are unlimited if (0 === $this->maxFiles) { diff --git a/src/Monolog/Logger.php b/src/Monolog/Logger.php index 430a9953..74ab2857 100644 --- a/src/Monolog/Logger.php +++ b/src/Monolog/Logger.php @@ -316,9 +316,9 @@ class Logger implements LoggerInterface } if ($this->microsecondTimestamps) { - $ts = \DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)), $this->timezone); + $ts = \DateTimeImmutable::createFromFormat('U.u', sprintf('%.6F', microtime(true)), $this->timezone); } else { - $ts = new \DateTime('', $this->timezone); + $ts = new \DateTimeImmutable('', $this->timezone); } $ts->setTimezone($this->timezone); diff --git a/src/Monolog/Test/TestCase.php b/src/Monolog/Test/TestCase.php index 5ec79e25..40b387c6 100644 --- a/src/Monolog/Test/TestCase.php +++ b/src/Monolog/Test/TestCase.php @@ -31,7 +31,7 @@ class TestCase extends \PHPUnit_Framework_TestCase 'level' => $level, 'level_name' => Logger::getLevelName($level), 'channel' => 'test', - 'datetime' => \DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true))), + 'datetime' => \DateTimeImmutable::createFromFormat('U.u', sprintf('%.6F', microtime(true))), 'extra' => array(), ); } diff --git a/tests/Monolog/Formatter/ChromePHPFormatterTest.php b/tests/Monolog/Formatter/ChromePHPFormatterTest.php index 71c42046..50a6d037 100644 --- a/tests/Monolog/Formatter/ChromePHPFormatterTest.php +++ b/tests/Monolog/Formatter/ChromePHPFormatterTest.php @@ -26,7 +26,7 @@ class ChromePHPFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'ERROR', 'channel' => 'meh', 'context' => array('from' => 'logger'), - 'datetime' => new \DateTime("@0"), + 'datetime' => new \DateTimeImmutable("@0"), 'extra' => array('ip' => '127.0.0.1'), 'message' => 'log', ); @@ -59,7 +59,7 @@ class ChromePHPFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'CRITICAL', 'channel' => 'meh', 'context' => array('from' => 'logger'), - 'datetime' => new \DateTime("@0"), + 'datetime' => new \DateTimeImmutable("@0"), 'extra' => array('ip' => '127.0.0.1', 'file' => 'test', 'line' => 14), 'message' => 'log', ); @@ -92,7 +92,7 @@ class ChromePHPFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'DEBUG', 'channel' => 'meh', 'context' => array(), - 'datetime' => new \DateTime("@0"), + 'datetime' => new \DateTimeImmutable("@0"), 'extra' => array(), 'message' => 'log', ); @@ -122,7 +122,7 @@ class ChromePHPFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'INFO', 'channel' => 'meh', 'context' => array(), - 'datetime' => new \DateTime("@0"), + 'datetime' => new \DateTimeImmutable("@0"), 'extra' => array(), 'message' => 'log', ), @@ -131,7 +131,7 @@ class ChromePHPFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'WARNING', 'channel' => 'foo', 'context' => array(), - 'datetime' => new \DateTime("@0"), + 'datetime' => new \DateTimeImmutable("@0"), 'extra' => array(), 'message' => 'log2', ), diff --git a/tests/Monolog/Formatter/ElasticaFormatterTest.php b/tests/Monolog/Formatter/ElasticaFormatterTest.php index 90cc48dd..428c27b3 100644 --- a/tests/Monolog/Formatter/ElasticaFormatterTest.php +++ b/tests/Monolog/Formatter/ElasticaFormatterTest.php @@ -35,7 +35,7 @@ class ElasticaFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'ERROR', 'channel' => 'meh', 'context' => array('foo' => 7, 'bar', 'class' => new \stdClass), - 'datetime' => new \DateTime("@0"), + 'datetime' => new \DateTimeImmutable("@0"), 'extra' => array(), 'message' => 'log', ); diff --git a/tests/Monolog/Formatter/FluentdFormatterTest.php b/tests/Monolog/Formatter/FluentdFormatterTest.php index 1aef5f81..828a3964 100644 --- a/tests/Monolog/Formatter/FluentdFormatterTest.php +++ b/tests/Monolog/Formatter/FluentdFormatterTest.php @@ -36,7 +36,7 @@ class FluentdFormatterTest extends TestCase public function testFormat() { $record = $this->getRecord(Logger::WARNING); - $record['datetime'] = new \DateTime("@0"); + $record['datetime'] = new \DateTimeImmutable("@0"); $formatter = new FluentdFormatter(); $this->assertEquals( @@ -51,7 +51,7 @@ class FluentdFormatterTest extends TestCase public function testFormatWithTag() { $record = $this->getRecord(Logger::ERROR); - $record['datetime'] = new \DateTime("@0"); + $record['datetime'] = new \DateTimeImmutable("@0"); $formatter = new FluentdFormatter(true); $this->assertEquals( diff --git a/tests/Monolog/Formatter/GelfMessageFormatterTest.php b/tests/Monolog/Formatter/GelfMessageFormatterTest.php index e6bd3098..34021fb7 100644 --- a/tests/Monolog/Formatter/GelfMessageFormatterTest.php +++ b/tests/Monolog/Formatter/GelfMessageFormatterTest.php @@ -33,7 +33,7 @@ class GelfMessageFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'ERROR', 'channel' => 'meh', 'context' => array(), - 'datetime' => new \DateTime("@0"), + 'datetime' => new \DateTimeImmutable("@0"), 'extra' => array(), 'message' => 'log', ); @@ -68,7 +68,7 @@ class GelfMessageFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'ERROR', 'channel' => 'meh', 'context' => array('from' => 'logger'), - 'datetime' => new \DateTime("@0"), + 'datetime' => new \DateTimeImmutable("@0"), 'extra' => array('file' => 'test', 'line' => 14), 'message' => 'log', ); @@ -106,7 +106,7 @@ class GelfMessageFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'ERROR', 'channel' => 'meh', 'context' => array('from' => 'logger'), - 'datetime' => new \DateTime("@0"), + 'datetime' => new \DateTimeImmutable("@0"), 'extra' => array('key' => 'pair'), 'message' => 'log', ); @@ -147,7 +147,7 @@ class GelfMessageFormatterTest extends \PHPUnit_Framework_TestCase 'file' => '/some/file/in/dir.php:56', 'trace' => array('/some/file/1.php:23', '/some/file/2.php:3'), )), - 'datetime' => new \DateTime("@0"), + 'datetime' => new \DateTimeImmutable("@0"), 'extra' => array(), 'message' => 'log', ); @@ -171,7 +171,7 @@ class GelfMessageFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'ERROR', 'channel' => 'meh', 'context' => array('from' => 'logger'), - 'datetime' => new \DateTime("@0"), + 'datetime' => new \DateTimeImmutable("@0"), 'extra' => array('key' => 'pair'), 'message' => 'log', ); @@ -205,7 +205,7 @@ class GelfMessageFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'ERROR', 'channel' => 'meh', 'context' => array('exception' => str_repeat(' ', 32767)), - 'datetime' => new \DateTime("@0"), + 'datetime' => new \DateTimeImmutable("@0"), 'extra' => array('key' => str_repeat(' ', 32767)), 'message' => 'log' ); diff --git a/tests/Monolog/Formatter/JsonFormatterTest.php b/tests/Monolog/Formatter/JsonFormatterTest.php index 68cde981..eb717567 100644 --- a/tests/Monolog/Formatter/JsonFormatterTest.php +++ b/tests/Monolog/Formatter/JsonFormatterTest.php @@ -84,7 +84,7 @@ class JsonFormatterTest extends TestCase 'level_name' => 'CRITICAL', 'channel' => 'core', 'context' => array('exception' => $exception), - 'datetime' => new \DateTime(), + 'datetime' => new \DateTimeImmutable(), 'extra' => array(), 'message' => 'foobar', )); @@ -94,7 +94,7 @@ class JsonFormatterTest extends TestCase } else { $path = substr(json_encode($exception->getFile()), 1, -1); } - $this->assertEquals('{"level_name":"CRITICAL","channel":"core","context":{"exception":{"class":"RuntimeException","message":"'.$exception->getMessage().'","code":'.$exception->getCode().',"file":"'.$path.':'.$exception->getLine().'"}},"datetime":'.json_encode(new \DateTime()).',"extra":[],"message":"foobar"}'."\n", $message); + $this->assertEquals('{"level_name":"CRITICAL","channel":"core","context":{"exception":{"class":"RuntimeException","message":"'.$exception->getMessage().'","code":'.$exception->getCode().',"file":"'.$path.':'.$exception->getLine().'"}},"datetime":'.json_encode(new \DateTimeImmutable()).',"extra":[],"message":"foobar"}'."\n", $message); } public function testDefFormatWithPreviousException() @@ -105,7 +105,7 @@ class JsonFormatterTest extends TestCase 'level_name' => 'CRITICAL', 'channel' => 'core', 'context' => array('exception' => $exception), - 'datetime' => new \DateTime(), + 'datetime' => new \DateTimeImmutable(), 'extra' => array(), 'message' => 'foobar', )); @@ -117,6 +117,6 @@ class JsonFormatterTest extends TestCase $pathPrevious = substr(json_encode($exception->getPrevious()->getFile()), 1, -1); $pathException = substr(json_encode($exception->getFile()), 1, -1); } - $this->assertEquals('{"level_name":"CRITICAL","channel":"core","context":{"exception":{"class":"RuntimeException","message":"'.$exception->getMessage().'","code":'.$exception->getCode().',"file":"'.$pathException.':'.$exception->getLine().'","previous":{"class":"LogicException","message":"'.$exception->getPrevious()->getMessage().'","code":'.$exception->getPrevious()->getCode().',"file":"'.$pathPrevious.':'.$exception->getPrevious()->getLine().'"}}},"datetime":'.json_encode(new \DateTime()).',"extra":[],"message":"foobar"}'."\n", $message); + $this->assertEquals('{"level_name":"CRITICAL","channel":"core","context":{"exception":{"class":"RuntimeException","message":"'.$exception->getMessage().'","code":'.$exception->getCode().',"file":"'.$pathException.':'.$exception->getLine().'","previous":{"class":"LogicException","message":"'.$exception->getPrevious()->getMessage().'","code":'.$exception->getPrevious()->getCode().',"file":"'.$pathPrevious.':'.$exception->getPrevious()->getLine().'"}}},"datetime":'.json_encode(new \DateTimeImmutable()).',"extra":[],"message":"foobar"}'."\n", $message); } } diff --git a/tests/Monolog/Formatter/LineFormatterTest.php b/tests/Monolog/Formatter/LineFormatterTest.php index 310d93ca..397c7f69 100644 --- a/tests/Monolog/Formatter/LineFormatterTest.php +++ b/tests/Monolog/Formatter/LineFormatterTest.php @@ -24,7 +24,7 @@ class LineFormatterTest extends \PHPUnit_Framework_TestCase 'channel' => 'log', 'context' => array(), 'message' => 'foo', - 'datetime' => new \DateTime, + 'datetime' => new \DateTimeImmutable, 'extra' => array(), )); $this->assertEquals('['.date('Y-m-d').'] log.WARNING: foo [] []'."\n", $message); @@ -37,7 +37,7 @@ class LineFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'ERROR', 'channel' => 'meh', 'message' => 'foo', - 'datetime' => new \DateTime, + 'datetime' => new \DateTimeImmutable, 'extra' => array(), 'context' => array( 'foo' => 'bar', @@ -56,7 +56,7 @@ class LineFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'ERROR', 'channel' => 'meh', 'context' => array(), - 'datetime' => new \DateTime, + 'datetime' => new \DateTimeImmutable, 'extra' => array('ip' => '127.0.0.1'), 'message' => 'log', )); @@ -70,7 +70,7 @@ class LineFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'ERROR', 'channel' => 'meh', 'context' => array(), - 'datetime' => new \DateTime, + 'datetime' => new \DateTimeImmutable, 'extra' => array('ip' => '127.0.0.1', 'file' => 'test'), 'message' => 'log', )); @@ -84,7 +84,7 @@ class LineFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'ERROR', 'channel' => 'meh', 'context' => array(), - 'datetime' => new \DateTime, + 'datetime' => new \DateTimeImmutable, 'extra' => array(), 'message' => 'log', )); @@ -98,7 +98,7 @@ class LineFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'ERROR', 'channel' => 'meh', 'context' => array('foo' => 'bar'), - 'datetime' => new \DateTime, + 'datetime' => new \DateTimeImmutable, 'extra' => array('foo' => 'xbar'), 'message' => 'log', )); @@ -112,7 +112,7 @@ class LineFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'ERROR', 'channel' => 'meh', 'context' => array(), - 'datetime' => new \DateTime, + 'datetime' => new \DateTimeImmutable, 'extra' => array('foo' => new TestFoo, 'bar' => new TestBar, 'baz' => array(), 'res' => fopen('php://memory', 'rb')), 'message' => 'foobar', )); @@ -127,7 +127,7 @@ class LineFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'CRITICAL', 'channel' => 'core', 'context' => array('exception' => new \RuntimeException('Foo')), - 'datetime' => new \DateTime, + 'datetime' => new \DateTimeImmutable, 'extra' => array(), 'message' => 'foobar', )); @@ -145,7 +145,7 @@ class LineFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'CRITICAL', 'channel' => 'core', 'context' => array('exception' => new \RuntimeException('Foo', 0, $previous)), - 'datetime' => new \DateTime, + 'datetime' => new \DateTimeImmutable, 'extra' => array(), 'message' => 'foobar', )); @@ -164,7 +164,7 @@ class LineFormatterTest extends \PHPUnit_Framework_TestCase 'channel' => 'test', 'message' => 'bar', 'context' => array(), - 'datetime' => new \DateTime, + 'datetime' => new \DateTimeImmutable, 'extra' => array(), ), array( @@ -172,7 +172,7 @@ class LineFormatterTest extends \PHPUnit_Framework_TestCase 'channel' => 'log', 'message' => 'foo', 'context' => array(), - 'datetime' => new \DateTime, + 'datetime' => new \DateTimeImmutable, 'extra' => array(), ), )); diff --git a/tests/Monolog/Formatter/LogglyFormatterTest.php b/tests/Monolog/Formatter/LogglyFormatterTest.php index 9fc853f5..ce5251b4 100644 --- a/tests/Monolog/Formatter/LogglyFormatterTest.php +++ b/tests/Monolog/Formatter/LogglyFormatterTest.php @@ -36,6 +36,6 @@ class LogglyFormatterTest extends TestCase $formatted_decoded = json_decode($formatter->format($record), true); $this->assertArrayNotHasKey("datetime", $formatted_decoded); $this->assertArrayHasKey("timestamp", $formatted_decoded); - $this->assertEquals(new \DateTime($formatted_decoded["timestamp"]), $record["datetime"]); + $this->assertEquals(new \DateTimeImmutable($formatted_decoded["timestamp"]), $record["datetime"]); } } diff --git a/tests/Monolog/Formatter/LogstashFormatterTest.php b/tests/Monolog/Formatter/LogstashFormatterTest.php index fc0df3b4..2fb6bf4e 100644 --- a/tests/Monolog/Formatter/LogstashFormatterTest.php +++ b/tests/Monolog/Formatter/LogstashFormatterTest.php @@ -33,7 +33,7 @@ class LogstashFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'ERROR', 'channel' => 'meh', 'context' => array(), - 'datetime' => new \DateTime("@0"), + 'datetime' => new \DateTimeImmutable("@0"), 'extra' => array(), 'message' => 'log', ); @@ -66,7 +66,7 @@ class LogstashFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'ERROR', 'channel' => 'meh', 'context' => array('from' => 'logger'), - 'datetime' => new \DateTime("@0"), + 'datetime' => new \DateTimeImmutable("@0"), 'extra' => array('file' => 'test', 'line' => 14), 'message' => 'log', ); @@ -88,7 +88,7 @@ class LogstashFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'ERROR', 'channel' => 'meh', 'context' => array('from' => 'logger'), - 'datetime' => new \DateTime("@0"), + 'datetime' => new \DateTimeImmutable("@0"), 'extra' => array('key' => 'pair'), 'message' => 'log', ); @@ -117,7 +117,7 @@ class LogstashFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'ERROR', 'channel' => 'meh', 'context' => array('from' => 'logger'), - 'datetime' => new \DateTime("@0"), + 'datetime' => new \DateTimeImmutable("@0"), 'extra' => array('key' => 'pair'), 'message' => 'log', ); @@ -143,7 +143,7 @@ class LogstashFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'ERROR', 'channel' => 'meh', 'context' => array('from' => 'logger'), - 'datetime' => new \DateTime("@0"), + 'datetime' => new \DateTimeImmutable("@0"), 'extra' => array('key' => 'pair'), 'message' => 'log', ); @@ -162,7 +162,7 @@ class LogstashFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'ERROR', 'channel' => '¯\_(ツ)_/¯', 'context' => array(), - 'datetime' => new \DateTime("@0"), + 'datetime' => new \DateTimeImmutable("@0"), 'extra' => array( 'user_agent' => "\xD6WN; FBCR/OrangeEspa\xF1a; Vers\xE3o/4.0; F\xE4rist", ), diff --git a/tests/Monolog/Formatter/MongoDBFormatterTest.php b/tests/Monolog/Formatter/MongoDBFormatterTest.php index 273e877c..84e75952 100644 --- a/tests/Monolog/Formatter/MongoDBFormatterTest.php +++ b/tests/Monolog/Formatter/MongoDBFormatterTest.php @@ -62,7 +62,7 @@ class MongoDBFormatterTest extends \PHPUnit_Framework_TestCase 'level' => Logger::WARNING, 'level_name' => Logger::getLevelName(Logger::WARNING), 'channel' => 'test', - 'datetime' => new \DateTime('2016-01-21T21:11:30.123456+00:00'), + 'datetime' => new \DateTimeImmutable('2016-01-21T21:11:30.123456+00:00'), 'extra' => array(), ); @@ -89,7 +89,7 @@ class MongoDBFormatterTest extends \PHPUnit_Framework_TestCase $record = array( 'message' => 'some log message', 'context' => array( - 'stuff' => new \DateTime('1969-01-21T21:11:30.123456+00:00'), + 'stuff' => new \DateTimeImmutable('1969-01-21T21:11:30.123456+00:00'), 'some_object' => $someObject, 'context_string' => 'some string', 'context_int' => 123456, @@ -98,7 +98,7 @@ class MongoDBFormatterTest extends \PHPUnit_Framework_TestCase 'level' => Logger::WARNING, 'level_name' => Logger::getLevelName(Logger::WARNING), 'channel' => 'test', - 'datetime' => new \DateTime('2016-01-21T21:11:30.123456+00:00'), + 'datetime' => new \DateTimeImmutable('2016-01-21T21:11:30.123456+00:00'), 'extra' => array(), ); @@ -145,7 +145,7 @@ class MongoDBFormatterTest extends \PHPUnit_Framework_TestCase 'level' => Logger::WARNING, 'level_name' => Logger::getLevelName(Logger::WARNING), 'channel' => 'test', - 'datetime' => new \DateTime('2016-01-21T21:11:30.123456+00:00'), + 'datetime' => new \DateTimeImmutable('2016-01-21T21:11:30.123456+00:00'), 'extra' => array(), ); @@ -181,7 +181,7 @@ class MongoDBFormatterTest extends \PHPUnit_Framework_TestCase 'level' => Logger::WARNING, 'level_name' => Logger::getLevelName(Logger::WARNING), 'channel' => 'test', - 'datetime' => new \DateTime('2016-01-21T21:11:30.123456+00:00'), + 'datetime' => new \DateTimeImmutable('2016-01-21T21:11:30.123456+00:00'), 'extra' => array(), ); @@ -220,7 +220,7 @@ class MongoDBFormatterTest extends \PHPUnit_Framework_TestCase 'level' => Logger::WARNING, 'level_name' => Logger::getLevelName(Logger::WARNING), 'channel' => 'test', - 'datetime' => new \DateTime('2016-01-21T21:11:30.123456+00:00'), + 'datetime' => new \DateTimeImmutable('2016-01-21T21:11:30.123456+00:00'), 'extra' => array(), ); @@ -249,7 +249,7 @@ class MongoDBFormatterTest extends \PHPUnit_Framework_TestCase 'level' => Logger::WARNING, 'level_name' => Logger::getLevelName(Logger::WARNING), 'channel' => 'test', - 'datetime' => new \DateTime('2016-01-21T21:11:30.123456+00:00'), + 'datetime' => new \DateTimeImmutable('2016-01-21T21:11:30.123456+00:00'), 'extra' => array(), ); diff --git a/tests/Monolog/Formatter/NormalizerFormatterTest.php b/tests/Monolog/Formatter/NormalizerFormatterTest.php index dd7bf6bc..c689266f 100644 --- a/tests/Monolog/Formatter/NormalizerFormatterTest.php +++ b/tests/Monolog/Formatter/NormalizerFormatterTest.php @@ -30,7 +30,7 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'ERROR', 'channel' => 'meh', 'message' => 'foo', - 'datetime' => new \DateTime, + 'datetime' => new \DateTimeImmutable, 'extra' => array('foo' => new TestFooNorm, 'bar' => new TestBarNorm, 'baz' => array(), 'res' => fopen('php://memory', 'rb')), 'context' => array( 'foo' => 'bar', @@ -103,7 +103,7 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase 'channel' => 'test', 'message' => 'bar', 'context' => array(), - 'datetime' => new \DateTime, + 'datetime' => new \DateTimeImmutable, 'extra' => array(), ), array( @@ -111,7 +111,7 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase 'channel' => 'log', 'message' => 'foo', 'context' => array(), - 'datetime' => new \DateTime, + 'datetime' => new \DateTimeImmutable, 'extra' => array(), ), )); diff --git a/tests/Monolog/Formatter/ScalarFormatterTest.php b/tests/Monolog/Formatter/ScalarFormatterTest.php index 87b60b69..eb237ae0 100644 --- a/tests/Monolog/Formatter/ScalarFormatterTest.php +++ b/tests/Monolog/Formatter/ScalarFormatterTest.php @@ -49,7 +49,7 @@ class ScalarFormatterTest extends \PHPUnit_Framework_TestCase 'baz' => false, 'bam' => array(1, 2, 3), 'bat' => array('foo' => 'bar'), - 'bap' => \DateTime::createFromFormat(\DateTime::ISO8601, '1970-01-01T00:00:00+0000'), + 'bap' => \DateTimeImmutable::createFromFormat(\DateTime::ISO8601, '1970-01-01T00:00:00+0000'), 'ban' => $exception, )); diff --git a/tests/Monolog/Formatter/WildfireFormatterTest.php b/tests/Monolog/Formatter/WildfireFormatterTest.php index 52f15a36..67d44d0c 100644 --- a/tests/Monolog/Formatter/WildfireFormatterTest.php +++ b/tests/Monolog/Formatter/WildfireFormatterTest.php @@ -26,7 +26,7 @@ class WildfireFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'ERROR', 'channel' => 'meh', 'context' => array('from' => 'logger'), - 'datetime' => new \DateTime("@0"), + 'datetime' => new \DateTimeImmutable("@0"), 'extra' => array('ip' => '127.0.0.1'), 'message' => 'log', ); @@ -51,7 +51,7 @@ class WildfireFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'ERROR', 'channel' => 'meh', 'context' => array('from' => 'logger'), - 'datetime' => new \DateTime("@0"), + 'datetime' => new \DateTimeImmutable("@0"), 'extra' => array('ip' => '127.0.0.1', 'file' => 'test', 'line' => 14), 'message' => 'log', ); @@ -76,7 +76,7 @@ class WildfireFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'ERROR', 'channel' => 'meh', 'context' => array(), - 'datetime' => new \DateTime("@0"), + 'datetime' => new \DateTimeImmutable("@0"), 'extra' => array(), 'message' => 'log', ); @@ -101,7 +101,7 @@ class WildfireFormatterTest extends \PHPUnit_Framework_TestCase 'level_name' => 'ERROR', 'channel' => 'meh', 'context' => array(), - 'datetime' => new \DateTime("@0"), + 'datetime' => new \DateTimeImmutable("@0"), 'extra' => array(), 'message' => 'log', ); @@ -127,7 +127,7 @@ class WildfireFormatterTest extends \PHPUnit_Framework_TestCase array('bar1', 'bar2', 'bar3'), ), ), - 'datetime' => new \DateTime("@0"), + 'datetime' => new \DateTimeImmutable("@0"), 'extra' => array(), 'message' => 'table-message', ); diff --git a/tests/Monolog/Handler/DeduplicationHandlerTest.php b/tests/Monolog/Handler/DeduplicationHandlerTest.php index 5e73e6db..6b9fdfd1 100644 --- a/tests/Monolog/Handler/DeduplicationHandlerTest.php +++ b/tests/Monolog/Handler/DeduplicationHandlerTest.php @@ -88,10 +88,10 @@ class DeduplicationHandlerTest extends TestCase $handler = new DeduplicationHandler($test, sys_get_temp_dir().'/monolog_dedup.log', 0); $record = $this->getRecord(Logger::ERROR); - $record['datetime']->modify('+62seconds'); + $record['datetime'] = $record['datetime']->modify('+62seconds'); $handler->handle($record); $record = $this->getRecord(Logger::CRITICAL); - $record['datetime']->modify('+62seconds'); + $record['datetime'] = $record['datetime']->modify('+62seconds'); $handler->handle($record); $handler->flush(); @@ -115,13 +115,13 @@ class DeduplicationHandlerTest extends TestCase // handle two records from yesterday, and one recent $record = $this->getRecord(Logger::ERROR); - $record['datetime']->modify('-1day -10seconds'); + $record['datetime'] = $record['datetime']->modify('-1day -10seconds'); $handler->handle($record); $record2 = $this->getRecord(Logger::CRITICAL); - $record2['datetime']->modify('-1day -10seconds'); + $record2['datetime'] = $record2['datetime']->modify('-1day -10seconds'); $handler->handle($record2); $record3 = $this->getRecord(Logger::CRITICAL); - $record3['datetime']->modify('-30seconds'); + $record3['datetime'] = $record3['datetime']->modify('-30seconds'); $handler->handle($record3); // log is written as none of them are duplicate diff --git a/tests/Monolog/Handler/ElasticSearchHandlerTest.php b/tests/Monolog/Handler/ElasticSearchHandlerTest.php index e40e3286..54965c16 100644 --- a/tests/Monolog/Handler/ElasticSearchHandlerTest.php +++ b/tests/Monolog/Handler/ElasticSearchHandlerTest.php @@ -62,7 +62,7 @@ class ElasticSearchHandlerTest extends TestCase 'level_name' => 'ERROR', 'channel' => 'meh', 'context' => array('foo' => 7, 'bar', 'class' => new \stdClass), - 'datetime' => new \DateTime("@0"), + 'datetime' => new \DateTimeImmutable("@0"), 'extra' => array(), 'message' => 'log', ); @@ -167,7 +167,7 @@ class ElasticSearchHandlerTest extends TestCase 'level_name' => 'ERROR', 'channel' => 'meh', 'context' => array('foo' => 7, 'bar', 'class' => new \stdClass), - 'datetime' => new \DateTime("@0"), + 'datetime' => new \DateTimeImmutable("@0"), 'extra' => array(), 'message' => 'log', ); diff --git a/tests/Monolog/Handler/FleepHookHandlerTest.php b/tests/Monolog/Handler/FleepHookHandlerTest.php index 7f3952a3..9c40af94 100644 --- a/tests/Monolog/Handler/FleepHookHandlerTest.php +++ b/tests/Monolog/Handler/FleepHookHandlerTest.php @@ -62,7 +62,7 @@ class FleepHookHandlerTest extends TestCase 'level' => Logger::DEBUG, 'level_name' => Logger::getLevelName(Logger::DEBUG), 'channel' => 'channel', - 'datetime' => new \DateTime(), + 'datetime' => new \DateTimeImmutable(), 'extra' => array(), ); diff --git a/tests/Monolog/Handler/HipChatHandlerTest.php b/tests/Monolog/Handler/HipChatHandlerTest.php index 4481a341..fc773b44 100644 --- a/tests/Monolog/Handler/HipChatHandlerTest.php +++ b/tests/Monolog/Handler/HipChatHandlerTest.php @@ -171,29 +171,29 @@ class HipChatHandlerTest extends TestCase return array( array( array( - array('level' => Logger::WARNING, 'message' => 'Oh bugger!', 'level_name' => 'warning', 'datetime' => new \DateTime()), - array('level' => Logger::NOTICE, 'message' => 'Something noticeable happened.', 'level_name' => 'notice', 'datetime' => new \DateTime()), - array('level' => Logger::CRITICAL, 'message' => 'Everything is broken!', 'level_name' => 'critical', 'datetime' => new \DateTime()), + array('level' => Logger::WARNING, 'message' => 'Oh bugger!', 'level_name' => 'warning', 'datetime' => new \DateTimeImmutable()), + array('level' => Logger::NOTICE, 'message' => 'Something noticeable happened.', 'level_name' => 'notice', 'datetime' => new \DateTimeImmutable()), + array('level' => Logger::CRITICAL, 'message' => 'Everything is broken!', 'level_name' => 'critical', 'datetime' => new \DateTimeImmutable()), ), 'red', ), array( array( - array('level' => Logger::WARNING, 'message' => 'Oh bugger!', 'level_name' => 'warning', 'datetime' => new \DateTime()), - array('level' => Logger::NOTICE, 'message' => 'Something noticeable happened.', 'level_name' => 'notice', 'datetime' => new \DateTime()), + array('level' => Logger::WARNING, 'message' => 'Oh bugger!', 'level_name' => 'warning', 'datetime' => new \DateTimeImmutable()), + array('level' => Logger::NOTICE, 'message' => 'Something noticeable happened.', 'level_name' => 'notice', 'datetime' => new \DateTimeImmutable()), ), 'yellow', ), array( array( - array('level' => Logger::DEBUG, 'message' => 'Just debugging.', 'level_name' => 'debug', 'datetime' => new \DateTime()), - array('level' => Logger::NOTICE, 'message' => 'Something noticeable happened.', 'level_name' => 'notice', 'datetime' => new \DateTime()), + array('level' => Logger::DEBUG, 'message' => 'Just debugging.', 'level_name' => 'debug', 'datetime' => new \DateTimeImmutable()), + array('level' => Logger::NOTICE, 'message' => 'Something noticeable happened.', 'level_name' => 'notice', 'datetime' => new \DateTimeImmutable()), ), 'green', ), array( array( - array('level' => Logger::DEBUG, 'message' => 'Just debugging.', 'level_name' => 'debug', 'datetime' => new \DateTime()), + array('level' => Logger::DEBUG, 'message' => 'Just debugging.', 'level_name' => 'debug', 'datetime' => new \DateTimeImmutable()), ), 'gray', ),