| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- /*
- * This file is part of the Monolog package.
- *
- * (c) Jordi Boggiano <j.boggiano@seld.be>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Monolog\Formatter;
- /**
- * @covers Monolog\Formatter\NormalizerFormatter
- */
- class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
- {
- public function testFormat()
- {
- $formatter = new NormalizerFormatter('Y-m-d');
- $formatted = $formatter->format(array(
- 'level_name' => 'ERROR',
- 'channel' => 'meh',
- 'message' => 'foo',
- 'datetime' => new \DateTime,
- 'extra' => array('foo' => new TestFooNorm, 'bar' => new TestBarNorm, 'baz' => array(), 'res' => fopen('php://memory', 'rb')),
- 'context' => array(
- 'foo' => 'bar',
- 'baz' => 'qux',
- )
- ));
- $this->assertEquals(array(
- 'level_name' => 'ERROR',
- 'channel' => 'meh',
- 'message' => 'foo',
- 'datetime' => date('Y-m-d'),
- 'extra' => array(
- 'foo' => '[object] (Monolog\\Formatter\\TestFooNorm: {"foo":"foo"})',
- 'bar' => '[object] (Monolog\\Formatter\\TestBarNorm: {})',
- 'baz' => array(),
- 'res' => '[resource]',
- ),
- 'context' => array(
- 'foo' => 'bar',
- 'baz' => 'qux',
- )
- ), $formatted);
- }
- public function testBatchFormat()
- {
- $formatter = new NormalizerFormatter('Y-m-d');
- $formatted = $formatter->formatBatch(array(
- array(
- 'level_name' => 'CRITICAL',
- 'channel' => 'test',
- 'message' => 'bar',
- 'context' => array(),
- 'datetime' => new \DateTime,
- 'extra' => array(),
- ),
- array(
- 'level_name' => 'WARNING',
- 'channel' => 'log',
- 'message' => 'foo',
- 'context' => array(),
- 'datetime' => new \DateTime,
- 'extra' => array(),
- ),
- ));
- $this->assertEquals(array(
- array(
- 'level_name' => 'CRITICAL',
- 'channel' => 'test',
- 'message' => 'bar',
- 'context' => array(),
- 'datetime' => date('Y-m-d'),
- 'extra' => array(),
- ),
- array(
- 'level_name' => 'WARNING',
- 'channel' => 'log',
- 'message' => 'foo',
- 'context' => array(),
- 'datetime' => date('Y-m-d'),
- 'extra' => array(),
- ),
- ), $formatted);
- }
- }
- class TestFooNorm
- {
- public $foo = 'foo';
- }
- class TestBarNorm
- {
- public function __toString()
- {
- return 'bar';
- }
- }
|