diff options
Diffstat (limited to 'tests/Monolog/Formatter/MongoDBFormatterTest.php')
-rw-r--r-- | tests/Monolog/Formatter/MongoDBFormatterTest.php | 156 |
1 files changed, 78 insertions, 78 deletions
diff --git a/tests/Monolog/Formatter/MongoDBFormatterTest.php b/tests/Monolog/Formatter/MongoDBFormatterTest.php index 52e699e..8759c01 100644 --- a/tests/Monolog/Formatter/MongoDBFormatterTest.php +++ b/tests/Monolog/Formatter/MongoDBFormatterTest.php @@ -1,4 +1,4 @@ -<?php +<?php declare(strict_types=1); /* * This file is part of the Monolog package. @@ -16,21 +16,21 @@ use Monolog\Logger; /** * @author Florian Plattner <me@florianplattner.de> */ -class MongoDBFormatterTest extends \PHPUnit_Framework_TestCase +class MongoDBFormatterTest extends \PHPUnit\Framework\TestCase { public function setUp() { - if (!class_exists('MongoDate')) { - $this->markTestSkipped('mongo extension not installed'); + if (!class_exists('MongoDB\BSON\UTCDateTime')) { + $this->markTestSkipped('ext-mongodb not installed'); } } public function constructArgumentProvider() { - return array( - array(1, true, 1, true), - array(0, false, 0, false), - ); + return [ + [1, true, 1, true], + [0, false, 0, false], + ]; } /** @@ -56,28 +56,28 @@ class MongoDBFormatterTest extends \PHPUnit_Framework_TestCase public function testSimpleFormat() { - $record = array( + $record = [ 'message' => 'some log message', - 'context' => array(), + 'context' => [], 'level' => Logger::WARNING, 'level_name' => Logger::getLevelName(Logger::WARNING), 'channel' => 'test', - 'datetime' => new \DateTime('2014-02-01 00:00:00'), - 'extra' => array(), - ); + 'datetime' => new \DateTimeImmutable('2016-01-21T21:11:30.123456+00:00'), + 'extra' => [], + ]; $formatter = new MongoDBFormatter(); $formattedRecord = $formatter->format($record); $this->assertCount(7, $formattedRecord); $this->assertEquals('some log message', $formattedRecord['message']); - $this->assertEquals(array(), $formattedRecord['context']); + $this->assertEquals([], $formattedRecord['context']); $this->assertEquals(Logger::WARNING, $formattedRecord['level']); $this->assertEquals(Logger::getLevelName(Logger::WARNING), $formattedRecord['level_name']); $this->assertEquals('test', $formattedRecord['channel']); - $this->assertInstanceOf('\MongoDate', $formattedRecord['datetime']); - $this->assertEquals('0.00000000 1391212800', $formattedRecord['datetime']->__toString()); - $this->assertEquals(array(), $formattedRecord['extra']); + $this->assertInstanceOf('MongoDB\BSON\UTCDateTime', $formattedRecord['datetime']); + $this->assertEquals('1453410690123', $formattedRecord['datetime']->__toString()); + $this->assertEquals([], $formattedRecord['extra']); } public function testRecursiveFormat() @@ -86,34 +86,34 @@ class MongoDBFormatterTest extends \PHPUnit_Framework_TestCase $someObject->foo = 'something'; $someObject->bar = 'stuff'; - $record = array( + $record = [ 'message' => 'some log message', - 'context' => array( - 'stuff' => new \DateTime('2014-02-01 02:31:33'), + 'context' => [ + 'stuff' => new \DateTimeImmutable('1969-01-21T21:11:30.213000+00:00'), 'some_object' => $someObject, 'context_string' => 'some string', 'context_int' => 123456, 'except' => new \Exception('exception message', 987), - ), + ], 'level' => Logger::WARNING, 'level_name' => Logger::getLevelName(Logger::WARNING), 'channel' => 'test', - 'datetime' => new \DateTime('2014-02-01 00:00:00'), - 'extra' => array(), - ); + 'datetime' => new \DateTimeImmutable('2016-01-21T21:11:30.213000+00:00'), + 'extra' => [], + ]; $formatter = new MongoDBFormatter(); $formattedRecord = $formatter->format($record); $this->assertCount(5, $formattedRecord['context']); - $this->assertInstanceOf('\MongoDate', $formattedRecord['context']['stuff']); - $this->assertEquals('0.00000000 1391221893', $formattedRecord['context']['stuff']->__toString()); + $this->assertInstanceOf('MongoDB\BSON\UTCDateTime', $formattedRecord['context']['stuff']); + $this->assertEquals('-29731710213', $formattedRecord['context']['stuff']->__toString()); $this->assertEquals( - array( + [ 'foo' => 'something', 'bar' => 'stuff', 'class' => 'stdClass', - ), + ], $formattedRecord['context']['some_object'] ); $this->assertEquals('some string', $formattedRecord['context']['context_string']); @@ -130,75 +130,75 @@ class MongoDBFormatterTest extends \PHPUnit_Framework_TestCase public function testFormatDepthArray() { - $record = array( + $record = [ 'message' => 'some log message', - 'context' => array( - 'nest2' => array( + 'context' => [ + 'nest2' => [ 'property' => 'anything', - 'nest3' => array( + 'nest3' => [ 'nest4' => 'value', 'property' => 'nothing', - ), - ), - ), + ], + ], + ], 'level' => Logger::WARNING, 'level_name' => Logger::getLevelName(Logger::WARNING), 'channel' => 'test', - 'datetime' => new \DateTime('2014-02-01 00:00:00'), - 'extra' => array(), - ); + 'datetime' => new \DateTimeImmutable('2016-01-21T21:11:30.123456+00:00'), + 'extra' => [], + ]; $formatter = new MongoDBFormatter(2); $formattedResult = $formatter->format($record); $this->assertEquals( - array( - 'nest2' => array( + [ + 'nest2' => [ 'property' => 'anything', 'nest3' => '[...]', - ), - ), + ], + ], $formattedResult['context'] ); } public function testFormatDepthArrayInfiniteNesting() { - $record = array( + $record = [ 'message' => 'some log message', - 'context' => array( - 'nest2' => array( + 'context' => [ + 'nest2' => [ 'property' => 'something', - 'nest3' => array( + 'nest3' => [ 'property' => 'anything', - 'nest4' => array( + 'nest4' => [ 'property' => 'nothing', - ), - ), - ), - ), + ], + ], + ], + ], 'level' => Logger::WARNING, 'level_name' => Logger::getLevelName(Logger::WARNING), 'channel' => 'test', - 'datetime' => new \DateTime('2014-02-01 00:00:00'), - 'extra' => array(), - ); + 'datetime' => new \DateTimeImmutable('2016-01-21T21:11:30.123456+00:00'), + 'extra' => [], + ]; $formatter = new MongoDBFormatter(0); $formattedResult = $formatter->format($record); $this->assertEquals( - array( - 'nest2' => array( + [ + 'nest2' => [ 'property' => 'something', - 'nest3' => array( + 'nest3' => [ 'property' => 'anything', - 'nest4' => array( + 'nest4' => [ 'property' => 'nothing', - ), - ), - ), - ), + ], + ], + ], + ], $formattedResult['context'] ); } @@ -211,46 +211,46 @@ class MongoDBFormatterTest extends \PHPUnit_Framework_TestCase $someObject->nest3->property = 'nothing'; $someObject->nest3->nest4 = 'invisible'; - $record = array( + $record = [ 'message' => 'some log message', - 'context' => array( + 'context' => [ 'nest2' => $someObject, - ), + ], 'level' => Logger::WARNING, 'level_name' => Logger::getLevelName(Logger::WARNING), 'channel' => 'test', - 'datetime' => new \DateTime('2014-02-01 00:00:00'), - 'extra' => array(), - ); + 'datetime' => new \DateTimeImmutable('2016-01-21T21:11:30.123456+00:00'), + 'extra' => [], + ]; $formatter = new MongoDBFormatter(2, true); $formattedResult = $formatter->format($record); $this->assertEquals( - array( - 'nest2' => array( + [ + 'nest2' => [ 'property' => 'anything', 'nest3' => '[...]', 'class' => 'stdClass', - ), - ), + ], + ], $formattedResult['context'] ); } public function testFormatDepthException() { - $record = array( + $record = [ 'message' => 'some log message', - 'context' => array( + 'context' => [ 'nest2' => new \Exception('exception message', 987), - ), + ], 'level' => Logger::WARNING, 'level_name' => Logger::getLevelName(Logger::WARNING), 'channel' => 'test', - 'datetime' => new \DateTime('2014-02-01 00:00:00'), - 'extra' => array(), - ); + 'datetime' => new \DateTimeImmutable('2016-01-21T21:11:30.123456+00:00'), + 'extra' => [], + ]; $formatter = new MongoDBFormatter(2, false); $formattedRecord = $formatter->format($record); |