Пример #1
0
 public function testFormatNoInfiniteLoopOnSelfReferencingArrayValues()
 {
     $datetime = new DateTime();
     $formatter = new BaseFormatter();
     $selfRefArr = array();
     $selfRefArr['selfRefArr'] =& $selfRefArr;
     $event = array('timestamp' => $datetime, 'priority' => 1, 'message' => 'tottakai', 'extra' => array('selfRefArr' => $selfRefArr));
     if (version_compare(PHP_VERSION, '5.5', 'lt')) {
         $outputExpected = array('timestamp' => $datetime->format($formatter->getDateTimeFormat()), 'priority' => 1, 'message' => 'tottakai', 'extra' => array('selfRefArr' => '{"selfRefArr":{"selfRefArr":null}}'));
     } else {
         $outputExpected = array('timestamp' => $datetime->format($formatter->getDateTimeFormat()), 'priority' => 1, 'message' => 'tottakai', 'extra' => array('selfRefArr' => ''));
     }
     $this->assertEquals($outputExpected, $formatter->format($event));
 }
Пример #2
0
 public function testFormatAllTypes()
 {
     $datetime = new DateTime();
     $object = new stdClass();
     $object->foo = 'bar';
     $formatter = new BaseFormatter();
     $event = array('timestamp' => $datetime, 'priority' => 1, 'message' => 'tottakai', 'extra' => array('float' => 0.2, 'boolean' => false, 'array_empty' => array(), 'array' => range(0, 4), 'traversable_empty' => new EmptyIterator(), 'traversable' => new ArrayIterator(array('id', 42)), 'null' => null, 'object_empty' => new stdClass(), 'object' => $object, 'string object' => new StringObject(), 'resource' => fopen('php://stdout', 'w')));
     $outputExpected = array('timestamp' => $datetime->format($formatter->getDateTimeFormat()), 'priority' => 1, 'message' => 'tottakai', 'extra' => array('boolean' => false, 'float' => 0.2, 'array_empty' => '[]', 'array' => '[0,1,2,3,4]', 'traversable_empty' => '[]', 'traversable' => '["id",42]', 'null' => null, 'object_empty' => 'object(stdClass) {}', 'object' => 'object(stdClass) {"foo":"bar"}', 'string object' => 'Hello World', 'resource' => 'resource(stream)'));
     $this->assertEquals($outputExpected, $formatter->format($event));
 }