1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-19 07:36:17 +02:00
Files
php-monolog/tests/Monolog/Formatter/NormalizerFormatterTest.php
Jordi Boggiano da33c84d07 CS fixes
2012-06-14 15:47:01 +02:00

106 lines
2.9 KiB
PHP

<?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';
}
}