mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-21 12:22:21 +02:00
Split off line formatter in normalizer + line formatters
This commit is contained in:
@@ -88,7 +88,11 @@ class LineFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
'extra' => array('foo' => new TestFoo, 'bar' => new TestBar, 'baz' => array(), 'res' => fopen('php://memory', 'rb')),
|
||||
'message' => 'foobar',
|
||||
));
|
||||
$this->assertEquals('['.date('Y-m-d').'] meh.ERROR: foobar [] {"foo":"[object] (Monolog\\Formatter\\TestFoo: {"foo":"foo"})","bar":"[object] (Monolog\\Formatter\\TestBar: {})","baz":[],"res":"[resource]"}'."\n", $message);
|
||||
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
|
||||
$this->assertEquals('['.date('Y-m-d').'] meh.ERROR: foobar [] {"foo":"[object] (Monolog\\\\Formatter\\\\TestFoo: {\\"foo\\":\\"foo\\"})","bar":"[object] (Monolog\\\\Formatter\\\\TestBar: {})","baz":[],"res":"[resource]"}'."\n", $message);
|
||||
} else {
|
||||
$this->assertEquals('['.date('Y-m-d').'] meh.ERROR: foobar [] {"foo":"[object] (Monolog\\Formatter\\TestFoo: {"foo":"foo"})","bar":"[object] (Monolog\\Formatter\\TestBar: {})","baz":[],"res":"[resource]"}'."\n", $message);
|
||||
}
|
||||
}
|
||||
|
||||
public function testBatchFormat()
|
||||
|
107
tests/Monolog/Formatter/NormalizerFormatterTest.php
Normal file
107
tests/Monolog/Formatter/NormalizerFormatterTest.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?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;
|
||||
|
||||
use Monolog\Logger;
|
||||
|
||||
/**
|
||||
* @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';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user