mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-21 12:22:21 +02:00
CS fixes
This commit is contained in:
@@ -21,29 +21,29 @@ class ChromePHPFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testDefaultFormat()
|
||||
{
|
||||
$formatter = new ChromePHPFormatter();
|
||||
$record = array(
|
||||
$record = [
|
||||
'level' => Logger::ERROR,
|
||||
'level_name' => 'ERROR',
|
||||
'channel' => 'meh',
|
||||
'context' => array('from' => 'logger'),
|
||||
'context' => ['from' => 'logger'],
|
||||
'datetime' => new \DateTimeImmutable("@0"),
|
||||
'extra' => array('ip' => '127.0.0.1'),
|
||||
'extra' => ['ip' => '127.0.0.1'],
|
||||
'message' => 'log',
|
||||
);
|
||||
];
|
||||
|
||||
$message = $formatter->format($record);
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
[
|
||||
'meh',
|
||||
array(
|
||||
[
|
||||
'message' => 'log',
|
||||
'context' => array('from' => 'logger'),
|
||||
'extra' => array('ip' => '127.0.0.1'),
|
||||
),
|
||||
'context' => ['from' => 'logger'],
|
||||
'extra' => ['ip' => '127.0.0.1'],
|
||||
],
|
||||
'unknown',
|
||||
'error',
|
||||
),
|
||||
],
|
||||
$message
|
||||
);
|
||||
}
|
||||
@@ -54,29 +54,29 @@ class ChromePHPFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testFormatWithFileAndLine()
|
||||
{
|
||||
$formatter = new ChromePHPFormatter();
|
||||
$record = array(
|
||||
$record = [
|
||||
'level' => Logger::CRITICAL,
|
||||
'level_name' => 'CRITICAL',
|
||||
'channel' => 'meh',
|
||||
'context' => array('from' => 'logger'),
|
||||
'context' => ['from' => 'logger'],
|
||||
'datetime' => new \DateTimeImmutable("@0"),
|
||||
'extra' => array('ip' => '127.0.0.1', 'file' => 'test', 'line' => 14),
|
||||
'extra' => ['ip' => '127.0.0.1', 'file' => 'test', 'line' => 14],
|
||||
'message' => 'log',
|
||||
);
|
||||
];
|
||||
|
||||
$message = $formatter->format($record);
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
[
|
||||
'meh',
|
||||
array(
|
||||
[
|
||||
'message' => 'log',
|
||||
'context' => array('from' => 'logger'),
|
||||
'extra' => array('ip' => '127.0.0.1'),
|
||||
),
|
||||
'context' => ['from' => 'logger'],
|
||||
'extra' => ['ip' => '127.0.0.1'],
|
||||
],
|
||||
'test : 14',
|
||||
'error',
|
||||
),
|
||||
],
|
||||
$message
|
||||
);
|
||||
}
|
||||
@@ -87,25 +87,25 @@ class ChromePHPFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testFormatWithoutContext()
|
||||
{
|
||||
$formatter = new ChromePHPFormatter();
|
||||
$record = array(
|
||||
$record = [
|
||||
'level' => Logger::DEBUG,
|
||||
'level_name' => 'DEBUG',
|
||||
'channel' => 'meh',
|
||||
'context' => array(),
|
||||
'context' => [],
|
||||
'datetime' => new \DateTimeImmutable("@0"),
|
||||
'extra' => array(),
|
||||
'extra' => [],
|
||||
'message' => 'log',
|
||||
);
|
||||
];
|
||||
|
||||
$message = $formatter->format($record);
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
[
|
||||
'meh',
|
||||
'log',
|
||||
'unknown',
|
||||
'log',
|
||||
),
|
||||
],
|
||||
$message
|
||||
);
|
||||
}
|
||||
@@ -116,42 +116,42 @@ class ChromePHPFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testBatchFormatThrowException()
|
||||
{
|
||||
$formatter = new ChromePHPFormatter();
|
||||
$records = array(
|
||||
array(
|
||||
$records = [
|
||||
[
|
||||
'level' => Logger::INFO,
|
||||
'level_name' => 'INFO',
|
||||
'channel' => 'meh',
|
||||
'context' => array(),
|
||||
'context' => [],
|
||||
'datetime' => new \DateTimeImmutable("@0"),
|
||||
'extra' => array(),
|
||||
'extra' => [],
|
||||
'message' => 'log',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'level' => Logger::WARNING,
|
||||
'level_name' => 'WARNING',
|
||||
'channel' => 'foo',
|
||||
'context' => array(),
|
||||
'context' => [],
|
||||
'datetime' => new \DateTimeImmutable("@0"),
|
||||
'extra' => array(),
|
||||
'extra' => [],
|
||||
'message' => 'log2',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
array(
|
||||
[
|
||||
[
|
||||
'meh',
|
||||
'log',
|
||||
'unknown',
|
||||
'info',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'foo',
|
||||
'log2',
|
||||
'unknown',
|
||||
'warn',
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
$formatter->formatBatch($records)
|
||||
);
|
||||
}
|
||||
|
@@ -30,24 +30,24 @@ class ElasticaFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testFormat()
|
||||
{
|
||||
// test log message
|
||||
$msg = array(
|
||||
$msg = [
|
||||
'level' => Logger::ERROR,
|
||||
'level_name' => 'ERROR',
|
||||
'channel' => 'meh',
|
||||
'context' => array('foo' => 7, 'bar', 'class' => new \stdClass),
|
||||
'context' => ['foo' => 7, 'bar', 'class' => new \stdClass],
|
||||
'datetime' => new \DateTimeImmutable("@0"),
|
||||
'extra' => array(),
|
||||
'extra' => [],
|
||||
'message' => 'log',
|
||||
);
|
||||
];
|
||||
|
||||
// expected values
|
||||
$expected = $msg;
|
||||
$expected['datetime'] = '1970-01-01T00:00:00.000000+00:00';
|
||||
$expected['context'] = array(
|
||||
$expected['context'] = [
|
||||
'class' => ['stdClass' => []],
|
||||
'foo' => 7,
|
||||
0 => 'bar',
|
||||
);
|
||||
];
|
||||
|
||||
// format log message
|
||||
$formatter = new ElasticaFormatter('my_index', 'doc_type');
|
||||
|
@@ -24,14 +24,14 @@ class FlowdockFormatterTest extends TestCase
|
||||
$formatter = new FlowdockFormatter('test_source', 'source@test.com');
|
||||
$record = $this->getRecord();
|
||||
|
||||
$expected = array(
|
||||
$expected = [
|
||||
'source' => 'test_source',
|
||||
'from_address' => 'source@test.com',
|
||||
'subject' => 'in test_source: WARNING - test',
|
||||
'content' => 'test',
|
||||
'tags' => array('#logs', '#warning', '#test'),
|
||||
'tags' => ['#logs', '#warning', '#test'],
|
||||
'project' => 'test_source',
|
||||
);
|
||||
];
|
||||
$formatted = $formatter->format($record);
|
||||
|
||||
$this->assertEquals($expected, $formatted['flowdock']);
|
||||
@@ -43,10 +43,10 @@ class FlowdockFormatterTest extends TestCase
|
||||
public function testFormatBatch()
|
||||
{
|
||||
$formatter = new FlowdockFormatter('test_source', 'source@test.com');
|
||||
$records = array(
|
||||
$records = [
|
||||
$this->getRecord(Logger::WARNING),
|
||||
$this->getRecord(Logger::DEBUG),
|
||||
);
|
||||
];
|
||||
$formatted = $formatter->formatBatch($records);
|
||||
|
||||
$this->assertArrayHasKey('flowdock', $formatted[0]);
|
||||
|
@@ -28,15 +28,15 @@ class GelfMessageFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testDefaultFormatter()
|
||||
{
|
||||
$formatter = new GelfMessageFormatter();
|
||||
$record = array(
|
||||
$record = [
|
||||
'level' => Logger::ERROR,
|
||||
'level_name' => 'ERROR',
|
||||
'channel' => 'meh',
|
||||
'context' => array(),
|
||||
'context' => [],
|
||||
'datetime' => new \DateTimeImmutable("@0"),
|
||||
'extra' => array(),
|
||||
'extra' => [],
|
||||
'message' => 'log',
|
||||
);
|
||||
];
|
||||
|
||||
$message = $formatter->format($record);
|
||||
|
||||
@@ -63,15 +63,15 @@ class GelfMessageFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testFormatWithFileAndLine()
|
||||
{
|
||||
$formatter = new GelfMessageFormatter();
|
||||
$record = array(
|
||||
$record = [
|
||||
'level' => Logger::ERROR,
|
||||
'level_name' => 'ERROR',
|
||||
'channel' => 'meh',
|
||||
'context' => array('from' => 'logger'),
|
||||
'context' => ['from' => 'logger'],
|
||||
'datetime' => new \DateTimeImmutable("@0"),
|
||||
'extra' => array('file' => 'test', 'line' => 14),
|
||||
'extra' => ['file' => 'test', 'line' => 14],
|
||||
'message' => 'log',
|
||||
);
|
||||
];
|
||||
|
||||
$message = $formatter->format($record);
|
||||
|
||||
@@ -87,10 +87,10 @@ class GelfMessageFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testFormatInvalidFails()
|
||||
{
|
||||
$formatter = new GelfMessageFormatter();
|
||||
$record = array(
|
||||
$record = [
|
||||
'level' => Logger::ERROR,
|
||||
'level_name' => 'ERROR',
|
||||
);
|
||||
];
|
||||
|
||||
$formatter->format($record);
|
||||
}
|
||||
@@ -101,15 +101,15 @@ class GelfMessageFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testFormatWithContext()
|
||||
{
|
||||
$formatter = new GelfMessageFormatter();
|
||||
$record = array(
|
||||
$record = [
|
||||
'level' => Logger::ERROR,
|
||||
'level_name' => 'ERROR',
|
||||
'channel' => 'meh',
|
||||
'context' => array('from' => 'logger'),
|
||||
'context' => ['from' => 'logger'],
|
||||
'datetime' => new \DateTimeImmutable("@0"),
|
||||
'extra' => array('key' => 'pair'),
|
||||
'extra' => ['key' => 'pair'],
|
||||
'message' => 'log',
|
||||
);
|
||||
];
|
||||
|
||||
$message = $formatter->format($record);
|
||||
|
||||
@@ -138,19 +138,19 @@ class GelfMessageFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testFormatWithContextContainingException()
|
||||
{
|
||||
$formatter = new GelfMessageFormatter();
|
||||
$record = array(
|
||||
$record = [
|
||||
'level' => Logger::ERROR,
|
||||
'level_name' => 'ERROR',
|
||||
'channel' => 'meh',
|
||||
'context' => array('from' => 'logger', 'exception' => array(
|
||||
'context' => ['from' => 'logger', 'exception' => [
|
||||
'class' => '\Exception',
|
||||
'file' => '/some/file/in/dir.php:56',
|
||||
'trace' => array('/some/file/1.php:23', '/some/file/2.php:3'),
|
||||
)),
|
||||
'trace' => ['/some/file/1.php:23', '/some/file/2.php:3'],
|
||||
]],
|
||||
'datetime' => new \DateTimeImmutable("@0"),
|
||||
'extra' => array(),
|
||||
'extra' => [],
|
||||
'message' => 'log',
|
||||
);
|
||||
];
|
||||
|
||||
$message = $formatter->format($record);
|
||||
|
||||
@@ -166,15 +166,15 @@ class GelfMessageFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testFormatWithExtra()
|
||||
{
|
||||
$formatter = new GelfMessageFormatter();
|
||||
$record = array(
|
||||
$record = [
|
||||
'level' => Logger::ERROR,
|
||||
'level_name' => 'ERROR',
|
||||
'channel' => 'meh',
|
||||
'context' => array('from' => 'logger'),
|
||||
'context' => ['from' => 'logger'],
|
||||
'datetime' => new \DateTimeImmutable("@0"),
|
||||
'extra' => array('key' => 'pair'),
|
||||
'extra' => ['key' => 'pair'],
|
||||
'message' => 'log',
|
||||
);
|
||||
];
|
||||
|
||||
$message = $formatter->format($record);
|
||||
|
||||
@@ -200,15 +200,15 @@ class GelfMessageFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testFormatWithLargeData()
|
||||
{
|
||||
$formatter = new GelfMessageFormatter();
|
||||
$record = array(
|
||||
$record = [
|
||||
'level' => Logger::ERROR,
|
||||
'level_name' => 'ERROR',
|
||||
'channel' => 'meh',
|
||||
'context' => array('exception' => str_repeat(' ', 32767)),
|
||||
'context' => ['exception' => str_repeat(' ', 32767)],
|
||||
'datetime' => new \DateTimeImmutable("@0"),
|
||||
'extra' => array('key' => str_repeat(' ', 32767)),
|
||||
'message' => 'log'
|
||||
);
|
||||
'extra' => ['key' => str_repeat(' ', 32767)],
|
||||
'message' => 'log',
|
||||
];
|
||||
$message = $formatter->format($record);
|
||||
$messageArray = $message->toArray();
|
||||
|
||||
@@ -216,7 +216,7 @@ class GelfMessageFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
$length = 200;
|
||||
|
||||
foreach ($messageArray as $key => $value) {
|
||||
if (!in_array($key, array('level', 'timestamp'))) {
|
||||
if (!in_array($key, ['level', 'timestamp'])) {
|
||||
$length += strlen($value);
|
||||
}
|
||||
}
|
||||
|
@@ -52,10 +52,10 @@ class JsonFormatterTest extends TestCase
|
||||
public function testFormatBatch()
|
||||
{
|
||||
$formatter = new JsonFormatter();
|
||||
$records = array(
|
||||
$records = [
|
||||
$this->getRecord(Logger::WARNING),
|
||||
$this->getRecord(Logger::DEBUG),
|
||||
);
|
||||
];
|
||||
$this->assertEquals(json_encode($records), $formatter->formatBatch($records));
|
||||
}
|
||||
|
||||
@@ -66,10 +66,10 @@ class JsonFormatterTest extends TestCase
|
||||
public function testFormatBatchNewlines()
|
||||
{
|
||||
$formatter = new JsonFormatter(JsonFormatter::BATCH_MODE_NEWLINES);
|
||||
$records = $expected = array(
|
||||
$records = $expected = [
|
||||
$this->getRecord(Logger::WARNING),
|
||||
$this->getRecord(Logger::DEBUG),
|
||||
);
|
||||
];
|
||||
array_walk($expected, function (&$value, $key) {
|
||||
$value = json_encode($value);
|
||||
});
|
||||
@@ -80,14 +80,14 @@ class JsonFormatterTest extends TestCase
|
||||
{
|
||||
$formatter = new JsonFormatter();
|
||||
$exception = new \RuntimeException('Foo');
|
||||
$message = $formatter->format(array(
|
||||
$message = $formatter->format([
|
||||
'level_name' => 'CRITICAL',
|
||||
'channel' => 'core',
|
||||
'context' => array('exception' => $exception),
|
||||
'context' => ['exception' => $exception],
|
||||
'datetime' => new \DateTimeImmutable(),
|
||||
'extra' => array(),
|
||||
'extra' => [],
|
||||
'message' => 'foobar',
|
||||
));
|
||||
]);
|
||||
|
||||
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
|
||||
$path = substr(json_encode($exception->getFile(), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), 1, -1);
|
||||
@@ -101,14 +101,14 @@ class JsonFormatterTest extends TestCase
|
||||
{
|
||||
$formatter = new JsonFormatter();
|
||||
$exception = new \RuntimeException('Foo', 0, new \LogicException('Wut?'));
|
||||
$message = $formatter->format(array(
|
||||
$message = $formatter->format([
|
||||
'level_name' => 'CRITICAL',
|
||||
'channel' => 'core',
|
||||
'context' => array('exception' => $exception),
|
||||
'context' => ['exception' => $exception],
|
||||
'datetime' => new \DateTimeImmutable(),
|
||||
'extra' => array(),
|
||||
'extra' => [],
|
||||
'message' => 'foobar',
|
||||
));
|
||||
]);
|
||||
|
||||
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
|
||||
$pathPrevious = substr(json_encode($exception->getPrevious()->getFile(), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), 1, -1);
|
||||
|
@@ -19,103 +19,103 @@ class LineFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testDefFormatWithString()
|
||||
{
|
||||
$formatter = new LineFormatter(null, 'Y-m-d');
|
||||
$message = $formatter->format(array(
|
||||
$message = $formatter->format([
|
||||
'level_name' => 'WARNING',
|
||||
'channel' => 'log',
|
||||
'context' => array(),
|
||||
'context' => [],
|
||||
'message' => 'foo',
|
||||
'datetime' => new \DateTimeImmutable,
|
||||
'extra' => array(),
|
||||
));
|
||||
'extra' => [],
|
||||
]);
|
||||
$this->assertEquals('['.date('Y-m-d').'] log.WARNING: foo [] []'."\n", $message);
|
||||
}
|
||||
|
||||
public function testDefFormatWithArrayContext()
|
||||
{
|
||||
$formatter = new LineFormatter(null, 'Y-m-d');
|
||||
$message = $formatter->format(array(
|
||||
$message = $formatter->format([
|
||||
'level_name' => 'ERROR',
|
||||
'channel' => 'meh',
|
||||
'message' => 'foo',
|
||||
'datetime' => new \DateTimeImmutable,
|
||||
'extra' => array(),
|
||||
'context' => array(
|
||||
'extra' => [],
|
||||
'context' => [
|
||||
'foo' => 'bar',
|
||||
'baz' => 'qux',
|
||||
'bool' => false,
|
||||
'null' => null,
|
||||
),
|
||||
));
|
||||
],
|
||||
]);
|
||||
$this->assertEquals('['.date('Y-m-d').'] meh.ERROR: foo {"foo":"bar","baz":"qux","bool":false,"null":null} []'."\n", $message);
|
||||
}
|
||||
|
||||
public function testDefFormatExtras()
|
||||
{
|
||||
$formatter = new LineFormatter(null, 'Y-m-d');
|
||||
$message = $formatter->format(array(
|
||||
$message = $formatter->format([
|
||||
'level_name' => 'ERROR',
|
||||
'channel' => 'meh',
|
||||
'context' => array(),
|
||||
'context' => [],
|
||||
'datetime' => new \DateTimeImmutable,
|
||||
'extra' => array('ip' => '127.0.0.1'),
|
||||
'extra' => ['ip' => '127.0.0.1'],
|
||||
'message' => 'log',
|
||||
));
|
||||
]);
|
||||
$this->assertEquals('['.date('Y-m-d').'] meh.ERROR: log [] {"ip":"127.0.0.1"}'."\n", $message);
|
||||
}
|
||||
|
||||
public function testFormatExtras()
|
||||
{
|
||||
$formatter = new LineFormatter("[%datetime%] %channel%.%level_name%: %message% %context% %extra.file% %extra%\n", 'Y-m-d');
|
||||
$message = $formatter->format(array(
|
||||
$message = $formatter->format([
|
||||
'level_name' => 'ERROR',
|
||||
'channel' => 'meh',
|
||||
'context' => array(),
|
||||
'context' => [],
|
||||
'datetime' => new \DateTimeImmutable,
|
||||
'extra' => array('ip' => '127.0.0.1', 'file' => 'test'),
|
||||
'extra' => ['ip' => '127.0.0.1', 'file' => 'test'],
|
||||
'message' => 'log',
|
||||
));
|
||||
]);
|
||||
$this->assertEquals('['.date('Y-m-d').'] meh.ERROR: log [] test {"ip":"127.0.0.1"}'."\n", $message);
|
||||
}
|
||||
|
||||
public function testContextAndExtraOptionallyNotShownIfEmpty()
|
||||
{
|
||||
$formatter = new LineFormatter(null, 'Y-m-d', false, true);
|
||||
$message = $formatter->format(array(
|
||||
$message = $formatter->format([
|
||||
'level_name' => 'ERROR',
|
||||
'channel' => 'meh',
|
||||
'context' => array(),
|
||||
'context' => [],
|
||||
'datetime' => new \DateTimeImmutable,
|
||||
'extra' => array(),
|
||||
'extra' => [],
|
||||
'message' => 'log',
|
||||
));
|
||||
]);
|
||||
$this->assertEquals('['.date('Y-m-d').'] meh.ERROR: log '."\n", $message);
|
||||
}
|
||||
|
||||
public function testContextAndExtraReplacement()
|
||||
{
|
||||
$formatter = new LineFormatter('%context.foo% => %extra.foo%');
|
||||
$message = $formatter->format(array(
|
||||
$message = $formatter->format([
|
||||
'level_name' => 'ERROR',
|
||||
'channel' => 'meh',
|
||||
'context' => array('foo' => 'bar'),
|
||||
'context' => ['foo' => 'bar'],
|
||||
'datetime' => new \DateTimeImmutable,
|
||||
'extra' => array('foo' => 'xbar'),
|
||||
'extra' => ['foo' => 'xbar'],
|
||||
'message' => 'log',
|
||||
));
|
||||
]);
|
||||
$this->assertEquals('bar => xbar', $message);
|
||||
}
|
||||
|
||||
public function testDefFormatWithObject()
|
||||
{
|
||||
$formatter = new LineFormatter(null, 'Y-m-d');
|
||||
$message = $formatter->format(array(
|
||||
$message = $formatter->format([
|
||||
'level_name' => 'ERROR',
|
||||
'channel' => 'meh',
|
||||
'context' => array(),
|
||||
'context' => [],
|
||||
'datetime' => new \DateTimeImmutable,
|
||||
'extra' => array('foo' => new TestFoo, 'bar' => new TestBar, 'baz' => array(), 'res' => fopen('php://memory', 'rb')),
|
||||
'extra' => ['foo' => new TestFoo, 'bar' => new TestBar, 'baz' => [], 'res' => fopen('php://memory', 'rb')],
|
||||
'message' => 'foobar',
|
||||
));
|
||||
]);
|
||||
|
||||
$this->assertEquals('['.date('Y-m-d').'] meh.ERROR: foobar [] {"foo":{"Monolog\\\\Formatter\\\\TestFoo":{"foo":"fooValue"}},"bar":{"Monolog\\\\Formatter\\\\TestBar":"bar"},"baz":[],"res":"[resource(stream)]"}'."\n", $message);
|
||||
}
|
||||
@@ -123,14 +123,14 @@ class LineFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testDefFormatWithException()
|
||||
{
|
||||
$formatter = new LineFormatter(null, 'Y-m-d');
|
||||
$message = $formatter->format(array(
|
||||
$message = $formatter->format([
|
||||
'level_name' => 'CRITICAL',
|
||||
'channel' => 'core',
|
||||
'context' => array('exception' => new \RuntimeException('Foo')),
|
||||
'context' => ['exception' => new \RuntimeException('Foo')],
|
||||
'datetime' => new \DateTimeImmutable,
|
||||
'extra' => array(),
|
||||
'extra' => [],
|
||||
'message' => 'foobar',
|
||||
));
|
||||
]);
|
||||
|
||||
$path = str_replace('\\/', '/', json_encode(__FILE__));
|
||||
|
||||
@@ -141,14 +141,14 @@ class LineFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$formatter = new LineFormatter(null, 'Y-m-d');
|
||||
$previous = new \LogicException('Wut?');
|
||||
$message = $formatter->format(array(
|
||||
$message = $formatter->format([
|
||||
'level_name' => 'CRITICAL',
|
||||
'channel' => 'core',
|
||||
'context' => array('exception' => new \RuntimeException('Foo', 0, $previous)),
|
||||
'context' => ['exception' => new \RuntimeException('Foo', 0, $previous)],
|
||||
'datetime' => new \DateTimeImmutable,
|
||||
'extra' => array(),
|
||||
'extra' => [],
|
||||
'message' => 'foobar',
|
||||
));
|
||||
]);
|
||||
|
||||
$path = str_replace('\\/', '/', json_encode(__FILE__));
|
||||
|
||||
@@ -158,24 +158,24 @@ class LineFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testBatchFormat()
|
||||
{
|
||||
$formatter = new LineFormatter(null, 'Y-m-d');
|
||||
$message = $formatter->formatBatch(array(
|
||||
array(
|
||||
$message = $formatter->formatBatch([
|
||||
[
|
||||
'level_name' => 'CRITICAL',
|
||||
'channel' => 'test',
|
||||
'message' => 'bar',
|
||||
'context' => array(),
|
||||
'context' => [],
|
||||
'datetime' => new \DateTimeImmutable,
|
||||
'extra' => array(),
|
||||
),
|
||||
array(
|
||||
'extra' => [],
|
||||
],
|
||||
[
|
||||
'level_name' => 'WARNING',
|
||||
'channel' => 'log',
|
||||
'message' => 'foo',
|
||||
'context' => array(),
|
||||
'context' => [],
|
||||
'datetime' => new \DateTimeImmutable,
|
||||
'extra' => array(),
|
||||
),
|
||||
));
|
||||
'extra' => [],
|
||||
],
|
||||
]);
|
||||
$this->assertEquals('['.date('Y-m-d').'] test.CRITICAL: bar [] []'."\n".'['.date('Y-m-d').'] log.WARNING: foo [] []'."\n", $message);
|
||||
}
|
||||
|
||||
@@ -183,11 +183,11 @@ class LineFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$formatter = new LineFormatter(null, 'Y-m-d');
|
||||
$message = $formatter->format(
|
||||
array(
|
||||
[
|
||||
'message' => "foo\nbar",
|
||||
'context' => array(),
|
||||
'extra' => array(),
|
||||
)
|
||||
'context' => [],
|
||||
'extra' => [],
|
||||
]
|
||||
);
|
||||
|
||||
$this->assertRegExp('/foo bar/', $message);
|
||||
@@ -197,11 +197,11 @@ class LineFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$formatter = new LineFormatter(null, 'Y-m-d', true);
|
||||
$message = $formatter->format(
|
||||
array(
|
||||
[
|
||||
'message' => "foo\nbar",
|
||||
'context' => array(),
|
||||
'extra' => array(),
|
||||
)
|
||||
'context' => [],
|
||||
'extra' => [],
|
||||
]
|
||||
);
|
||||
|
||||
$this->assertRegExp('/foo\nbar/', $message);
|
||||
|
@@ -28,15 +28,15 @@ class LogstashFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testDefaultFormatterV1()
|
||||
{
|
||||
$formatter = new LogstashFormatter('test', 'hostname', null, 'ctxt_');
|
||||
$record = array(
|
||||
$record = [
|
||||
'level' => Logger::ERROR,
|
||||
'level_name' => 'ERROR',
|
||||
'channel' => 'meh',
|
||||
'context' => array(),
|
||||
'context' => [],
|
||||
'datetime' => new \DateTimeImmutable("@0"),
|
||||
'extra' => array(),
|
||||
'extra' => [],
|
||||
'message' => 'log',
|
||||
);
|
||||
];
|
||||
|
||||
$message = json_decode($formatter->format($record), true);
|
||||
|
||||
@@ -61,15 +61,15 @@ class LogstashFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testFormatWithFileAndLineV1()
|
||||
{
|
||||
$formatter = new LogstashFormatter('test', null, null, 'ctxt_');
|
||||
$record = array(
|
||||
$record = [
|
||||
'level' => Logger::ERROR,
|
||||
'level_name' => 'ERROR',
|
||||
'channel' => 'meh',
|
||||
'context' => array('from' => 'logger'),
|
||||
'context' => ['from' => 'logger'],
|
||||
'datetime' => new \DateTimeImmutable("@0"),
|
||||
'extra' => array('file' => 'test', 'line' => 14),
|
||||
'extra' => ['file' => 'test', 'line' => 14],
|
||||
'message' => 'log',
|
||||
);
|
||||
];
|
||||
|
||||
$message = json_decode($formatter->format($record), true);
|
||||
|
||||
@@ -83,15 +83,15 @@ class LogstashFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testFormatWithContextV1()
|
||||
{
|
||||
$formatter = new LogstashFormatter('test', null, null, 'ctxt_');
|
||||
$record = array(
|
||||
$record = [
|
||||
'level' => Logger::ERROR,
|
||||
'level_name' => 'ERROR',
|
||||
'channel' => 'meh',
|
||||
'context' => array('from' => 'logger'),
|
||||
'context' => ['from' => 'logger'],
|
||||
'datetime' => new \DateTimeImmutable("@0"),
|
||||
'extra' => array('key' => 'pair'),
|
||||
'extra' => ['key' => 'pair'],
|
||||
'message' => 'log',
|
||||
);
|
||||
];
|
||||
|
||||
$message = json_decode($formatter->format($record), true);
|
||||
|
||||
@@ -112,15 +112,15 @@ class LogstashFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testFormatWithExtraV1()
|
||||
{
|
||||
$formatter = new LogstashFormatter('test', null, null, 'ctxt_');
|
||||
$record = array(
|
||||
$record = [
|
||||
'level' => Logger::ERROR,
|
||||
'level_name' => 'ERROR',
|
||||
'channel' => 'meh',
|
||||
'context' => array('from' => 'logger'),
|
||||
'context' => ['from' => 'logger'],
|
||||
'datetime' => new \DateTimeImmutable("@0"),
|
||||
'extra' => array('key' => 'pair'),
|
||||
'extra' => ['key' => 'pair'],
|
||||
'message' => 'log',
|
||||
);
|
||||
];
|
||||
|
||||
$message = json_decode($formatter->format($record), true);
|
||||
|
||||
@@ -138,15 +138,15 @@ class LogstashFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testFormatWithApplicationNameV1()
|
||||
{
|
||||
$formatter = new LogstashFormatter('app', 'test', null, 'ctxt_');
|
||||
$record = array(
|
||||
$record = [
|
||||
'level' => Logger::ERROR,
|
||||
'level_name' => 'ERROR',
|
||||
'channel' => 'meh',
|
||||
'context' => array('from' => 'logger'),
|
||||
'context' => ['from' => 'logger'],
|
||||
'datetime' => new \DateTimeImmutable("@0"),
|
||||
'extra' => array('key' => 'pair'),
|
||||
'extra' => ['key' => 'pair'],
|
||||
'message' => 'log',
|
||||
);
|
||||
];
|
||||
|
||||
$message = json_decode($formatter->format($record), true);
|
||||
|
||||
@@ -157,17 +157,17 @@ class LogstashFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testFormatWithLatin9Data()
|
||||
{
|
||||
$formatter = new LogstashFormatter('test', 'hostname');
|
||||
$record = array(
|
||||
$record = [
|
||||
'level' => Logger::ERROR,
|
||||
'level_name' => 'ERROR',
|
||||
'channel' => '¯\_(ツ)_/¯',
|
||||
'context' => array(),
|
||||
'context' => [],
|
||||
'datetime' => new \DateTimeImmutable("@0"),
|
||||
'extra' => array(
|
||||
'extra' => [
|
||||
'user_agent' => "\xD6WN; FBCR/OrangeEspa\xF1a; Vers\xE3o/4.0; F\xE4rist",
|
||||
),
|
||||
],
|
||||
'message' => 'log',
|
||||
);
|
||||
];
|
||||
|
||||
$message = json_decode($formatter->format($record), true);
|
||||
|
||||
|
@@ -27,10 +27,10 @@ class MongoDBFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
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 \DateTimeImmutable('2016-01-21T21:11:30.123456+00:00'),
|
||||
'extra' => array(),
|
||||
);
|
||||
'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('MongoDB\BSON\UTCDateTime', $formattedRecord['datetime']);
|
||||
$this->assertEquals('1453410690123', $formattedRecord['datetime']->__toString());
|
||||
$this->assertEquals(array(), $formattedRecord['extra']);
|
||||
$this->assertEquals([], $formattedRecord['extra']);
|
||||
}
|
||||
|
||||
public function testRecursiveFormat()
|
||||
@@ -86,21 +86,21 @@ class MongoDBFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
$someObject->foo = 'something';
|
||||
$someObject->bar = 'stuff';
|
||||
|
||||
$record = array(
|
||||
$record = [
|
||||
'message' => 'some log message',
|
||||
'context' => array(
|
||||
'context' => [
|
||||
'stuff' => new \DateTimeImmutable('1969-01-21T21:11:30.123456+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 \DateTimeImmutable('2016-01-21T21:11:30.123456+00:00'),
|
||||
'extra' => array(),
|
||||
);
|
||||
'extra' => [],
|
||||
];
|
||||
|
||||
$formatter = new MongoDBFormatter();
|
||||
$formattedRecord = $formatter->format($record);
|
||||
@@ -110,11 +110,11 @@ class MongoDBFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('-29731710123', $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']);
|
||||
@@ -131,75 +131,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 \DateTimeImmutable('2016-01-21T21:11:30.123456+00:00'),
|
||||
'extra' => array(),
|
||||
);
|
||||
'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 \DateTimeImmutable('2016-01-21T21:11:30.123456+00:00'),
|
||||
'extra' => array(),
|
||||
);
|
||||
'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']
|
||||
);
|
||||
}
|
||||
@@ -212,46 +212,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 \DateTimeImmutable('2016-01-21T21:11:30.123456+00:00'),
|
||||
'extra' => array(),
|
||||
);
|
||||
'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 \DateTimeImmutable('2016-01-21T21:11:30.123456+00:00'),
|
||||
'extra' => array(),
|
||||
);
|
||||
'extra' => [],
|
||||
];
|
||||
|
||||
$formatter = new MongoDBFormatter(2, false);
|
||||
$formattedRecord = $formatter->format($record);
|
||||
|
@@ -26,40 +26,40 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testFormat()
|
||||
{
|
||||
$formatter = new NormalizerFormatter('Y-m-d');
|
||||
$formatted = $formatter->format(array(
|
||||
$formatted = $formatter->format([
|
||||
'level_name' => 'ERROR',
|
||||
'channel' => 'meh',
|
||||
'message' => 'foo',
|
||||
'datetime' => new \DateTimeImmutable,
|
||||
'extra' => array('foo' => new TestFooNorm, 'bar' => new TestBarNorm, 'baz' => array(), 'res' => fopen('php://memory', 'rb')),
|
||||
'context' => array(
|
||||
'extra' => ['foo' => new TestFooNorm, 'bar' => new TestBarNorm, 'baz' => [], 'res' => fopen('php://memory', 'rb')],
|
||||
'context' => [
|
||||
'foo' => 'bar',
|
||||
'baz' => 'qux',
|
||||
'inf' => INF,
|
||||
'-inf' => -INF,
|
||||
'nan' => acos(4),
|
||||
),
|
||||
));
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertEquals(array(
|
||||
$this->assertEquals([
|
||||
'level_name' => 'ERROR',
|
||||
'channel' => 'meh',
|
||||
'message' => 'foo',
|
||||
'datetime' => date('Y-m-d'),
|
||||
'extra' => array(
|
||||
'extra' => [
|
||||
'foo' => ['Monolog\\Formatter\\TestFooNorm' => ["foo" => "fooValue"]],
|
||||
'bar' => ['Monolog\\Formatter\\TestBarNorm' => 'bar'],
|
||||
'baz' => array(),
|
||||
'baz' => [],
|
||||
'res' => '[resource(stream)]',
|
||||
),
|
||||
'context' => array(
|
||||
],
|
||||
'context' => [
|
||||
'foo' => 'bar',
|
||||
'baz' => 'qux',
|
||||
'inf' => 'INF',
|
||||
'-inf' => '-INF',
|
||||
'nan' => 'NaN',
|
||||
),
|
||||
), $formatted);
|
||||
],
|
||||
], $formatted);
|
||||
}
|
||||
|
||||
public function testFormatExceptions()
|
||||
@@ -67,72 +67,72 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
$formatter = new NormalizerFormatter('Y-m-d');
|
||||
$e = new \LogicException('bar');
|
||||
$e2 = new \RuntimeException('foo', 0, $e);
|
||||
$formatted = $formatter->format(array(
|
||||
$formatted = $formatter->format([
|
||||
'exception' => $e2,
|
||||
));
|
||||
]);
|
||||
|
||||
$this->assertGreaterThan(5, count($formatted['exception']['trace']));
|
||||
$this->assertTrue(isset($formatted['exception']['previous']));
|
||||
unset($formatted['exception']['trace'], $formatted['exception']['previous']);
|
||||
|
||||
$this->assertEquals(array(
|
||||
'exception' => array(
|
||||
$this->assertEquals([
|
||||
'exception' => [
|
||||
'class' => get_class($e2),
|
||||
'message' => $e2->getMessage(),
|
||||
'code' => $e2->getCode(),
|
||||
'file' => $e2->getFile().':'.$e2->getLine(),
|
||||
),
|
||||
), $formatted);
|
||||
],
|
||||
], $formatted);
|
||||
}
|
||||
|
||||
public function testFormatToStringExceptionHandle()
|
||||
{
|
||||
$formatter = new NormalizerFormatter('Y-m-d');
|
||||
$this->setExpectedException('RuntimeException', 'Could not convert to string');
|
||||
$formatter->format(array(
|
||||
$formatter->format([
|
||||
'myObject' => new TestToStringError(),
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
public function testBatchFormat()
|
||||
{
|
||||
$formatter = new NormalizerFormatter('Y-m-d');
|
||||
$formatted = $formatter->formatBatch(array(
|
||||
array(
|
||||
$formatted = $formatter->formatBatch([
|
||||
[
|
||||
'level_name' => 'CRITICAL',
|
||||
'channel' => 'test',
|
||||
'message' => 'bar',
|
||||
'context' => array(),
|
||||
'context' => [],
|
||||
'datetime' => new \DateTimeImmutable,
|
||||
'extra' => array(),
|
||||
),
|
||||
array(
|
||||
'extra' => [],
|
||||
],
|
||||
[
|
||||
'level_name' => 'WARNING',
|
||||
'channel' => 'log',
|
||||
'message' => 'foo',
|
||||
'context' => array(),
|
||||
'context' => [],
|
||||
'datetime' => new \DateTimeImmutable,
|
||||
'extra' => array(),
|
||||
),
|
||||
));
|
||||
$this->assertEquals(array(
|
||||
array(
|
||||
'extra' => [],
|
||||
],
|
||||
]);
|
||||
$this->assertEquals([
|
||||
[
|
||||
'level_name' => 'CRITICAL',
|
||||
'channel' => 'test',
|
||||
'message' => 'bar',
|
||||
'context' => array(),
|
||||
'context' => [],
|
||||
'datetime' => date('Y-m-d'),
|
||||
'extra' => array(),
|
||||
),
|
||||
array(
|
||||
'extra' => [],
|
||||
],
|
||||
[
|
||||
'level_name' => 'WARNING',
|
||||
'channel' => 'log',
|
||||
'message' => 'foo',
|
||||
'context' => array(),
|
||||
'context' => [],
|
||||
'datetime' => date('Y-m-d'),
|
||||
'extra' => array(),
|
||||
),
|
||||
), $formatted);
|
||||
'extra' => [],
|
||||
],
|
||||
], $formatted);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,11 +159,11 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
$formatter = new NormalizerFormatter();
|
||||
$reflMethod = new \ReflectionMethod($formatter, 'toJson');
|
||||
$reflMethod->setAccessible(true);
|
||||
$res = $reflMethod->invoke($formatter, array($foo, $bar), true);
|
||||
$res = $reflMethod->invoke($formatter, [$foo, $bar], true);
|
||||
|
||||
restore_error_handler();
|
||||
|
||||
$this->assertEquals(@json_encode(array($foo, $bar)), $res);
|
||||
$this->assertEquals(@json_encode([$foo, $bar]), $res);
|
||||
}
|
||||
|
||||
public function testIgnoresInvalidTypes()
|
||||
@@ -183,11 +183,11 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
$formatter = new NormalizerFormatter();
|
||||
$reflMethod = new \ReflectionMethod($formatter, 'toJson');
|
||||
$reflMethod->setAccessible(true);
|
||||
$res = $reflMethod->invoke($formatter, array($resource), true);
|
||||
$res = $reflMethod->invoke($formatter, [$resource], true);
|
||||
|
||||
restore_error_handler();
|
||||
|
||||
$this->assertEquals(@json_encode(array($resource)), $res);
|
||||
$this->assertEquals(@json_encode([$resource]), $res);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -211,7 +211,7 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
$reflMethod = new \ReflectionMethod($formatter, 'toJson');
|
||||
$reflMethod->setAccessible(true);
|
||||
|
||||
$res = $reflMethod->invoke($formatter, array('message' => "\xA4\xA6\xA8\xB4\xB8\xBC\xBD\xBE"));
|
||||
$res = $reflMethod->invoke($formatter, ['message' => "\xA4\xA6\xA8\xB4\xB8\xBC\xBD\xBE"]);
|
||||
|
||||
$this->assertSame('{"message":"€ŠšŽžŒœŸ"}', $res);
|
||||
}
|
||||
@@ -233,19 +233,19 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$obj = new \stdClass;
|
||||
|
||||
return array(
|
||||
'null' => array(null, null),
|
||||
'int' => array(123, 123),
|
||||
'float' => array(123.45, 123.45),
|
||||
'bool false' => array(false, false),
|
||||
'bool true' => array(true, true),
|
||||
'ascii string' => array('abcdef', 'abcdef'),
|
||||
'latin9 string' => array("\xB1\x31\xA4\xA6\xA8\xB4\xB8\xBC\xBD\xBE\xFF", '±1€ŠšŽžŒœŸÿ'),
|
||||
'unicode string' => array('¤¦¨´¸¼½¾€ŠšŽžŒœŸ', '¤¦¨´¸¼½¾€ŠšŽžŒœŸ'),
|
||||
'empty array' => array(array(), array()),
|
||||
'array' => array(array('abcdef'), array('abcdef')),
|
||||
'object' => array($obj, $obj),
|
||||
);
|
||||
return [
|
||||
'null' => [null, null],
|
||||
'int' => [123, 123],
|
||||
'float' => [123.45, 123.45],
|
||||
'bool false' => [false, false],
|
||||
'bool true' => [true, true],
|
||||
'ascii string' => ['abcdef', 'abcdef'],
|
||||
'latin9 string' => ["\xB1\x31\xA4\xA6\xA8\xB4\xB8\xBC\xBD\xBE\xFF", '±1€ŠšŽžŒœŸÿ'],
|
||||
'unicode string' => ['¤¦¨´¸¼½¾€ŠšŽžŒœŸ', '¤¦¨´¸¼½¾€ŠšŽžŒœŸ'],
|
||||
'empty array' => [[], []],
|
||||
'array' => [['abcdef'], ['abcdef']],
|
||||
'object' => [$obj, $obj],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -265,12 +265,12 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function providesHandleJsonErrorFailure()
|
||||
{
|
||||
return array(
|
||||
'depth' => array(JSON_ERROR_DEPTH, 'Maximum stack depth exceeded'),
|
||||
'state' => array(JSON_ERROR_STATE_MISMATCH, 'Underflow or the modes mismatch'),
|
||||
'ctrl' => array(JSON_ERROR_CTRL_CHAR, 'Unexpected control character found'),
|
||||
'default' => array(-1, 'Unknown error'),
|
||||
);
|
||||
return [
|
||||
'depth' => [JSON_ERROR_DEPTH, 'Maximum stack depth exceeded'],
|
||||
'state' => [JSON_ERROR_STATE_MISMATCH, 'Underflow or the modes mismatch'],
|
||||
'ctrl' => [JSON_ERROR_CTRL_CHAR, 'Unexpected control character found'],
|
||||
'default' => [-1, 'Unknown error'],
|
||||
];
|
||||
}
|
||||
|
||||
public function testExceptionTraceWithArgs()
|
||||
@@ -298,7 +298,7 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
$formatter = new NormalizerFormatter();
|
||||
$record = array('context' => array('exception' => $e));
|
||||
$record = ['context' => ['exception' => $e]];
|
||||
$result = $formatter->format($record);
|
||||
|
||||
$this->assertRegExp(
|
||||
|
@@ -24,7 +24,7 @@ class ScalarFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function buildTrace(\Exception $e)
|
||||
{
|
||||
$data = array();
|
||||
$data = [];
|
||||
$trace = $e->getTrace();
|
||||
foreach ($trace as $frame) {
|
||||
if (isset($frame['file'])) {
|
||||
@@ -45,64 +45,64 @@ class ScalarFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testFormat()
|
||||
{
|
||||
$exception = new \Exception('foo');
|
||||
$formatted = $this->formatter->format(array(
|
||||
$formatted = $this->formatter->format([
|
||||
'foo' => 'string',
|
||||
'bar' => 1,
|
||||
'baz' => false,
|
||||
'bam' => array(1, 2, 3),
|
||||
'bat' => array('foo' => 'bar'),
|
||||
'bam' => [1, 2, 3],
|
||||
'bat' => ['foo' => 'bar'],
|
||||
'bap' => $dt = new DateTimeImmutable(true),
|
||||
'ban' => $exception,
|
||||
));
|
||||
]);
|
||||
|
||||
$this->assertSame(array(
|
||||
$this->assertSame([
|
||||
'foo' => 'string',
|
||||
'bar' => 1,
|
||||
'baz' => false,
|
||||
'bam' => $this->encodeJson(array(1, 2, 3)),
|
||||
'bat' => $this->encodeJson(array('foo' => 'bar')),
|
||||
'bam' => $this->encodeJson([1, 2, 3]),
|
||||
'bat' => $this->encodeJson(['foo' => 'bar']),
|
||||
'bap' => (string) $dt,
|
||||
'ban' => $this->encodeJson(array(
|
||||
'ban' => $this->encodeJson([
|
||||
'class' => get_class($exception),
|
||||
'message' => $exception->getMessage(),
|
||||
'code' => $exception->getCode(),
|
||||
'file' => $exception->getFile() . ':' . $exception->getLine(),
|
||||
'trace' => $this->buildTrace($exception),
|
||||
)),
|
||||
), $formatted);
|
||||
]),
|
||||
], $formatted);
|
||||
}
|
||||
|
||||
public function testFormatWithErrorContext()
|
||||
{
|
||||
$context = array('file' => 'foo', 'line' => 1);
|
||||
$formatted = $this->formatter->format(array(
|
||||
$context = ['file' => 'foo', 'line' => 1];
|
||||
$formatted = $this->formatter->format([
|
||||
'context' => $context,
|
||||
));
|
||||
]);
|
||||
|
||||
$this->assertSame(array(
|
||||
$this->assertSame([
|
||||
'context' => $this->encodeJson($context),
|
||||
), $formatted);
|
||||
], $formatted);
|
||||
}
|
||||
|
||||
public function testFormatWithExceptionContext()
|
||||
{
|
||||
$exception = new \Exception('foo');
|
||||
$formatted = $this->formatter->format(array(
|
||||
'context' => array(
|
||||
$formatted = $this->formatter->format([
|
||||
'context' => [
|
||||
'exception' => $exception,
|
||||
),
|
||||
));
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertSame(array(
|
||||
'context' => $this->encodeJson(array(
|
||||
'exception' => array(
|
||||
$this->assertSame([
|
||||
'context' => $this->encodeJson([
|
||||
'exception' => [
|
||||
'class' => get_class($exception),
|
||||
'message' => $exception->getMessage(),
|
||||
'code' => $exception->getCode(),
|
||||
'file' => $exception->getFile() . ':' . $exception->getLine(),
|
||||
'trace' => $this->buildTrace($exception),
|
||||
),
|
||||
)),
|
||||
), $formatted);
|
||||
],
|
||||
]),
|
||||
], $formatted);
|
||||
}
|
||||
}
|
||||
|
@@ -21,15 +21,15 @@ class WildfireFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testDefaultFormat()
|
||||
{
|
||||
$wildfire = new WildfireFormatter();
|
||||
$record = array(
|
||||
$record = [
|
||||
'level' => Logger::ERROR,
|
||||
'level_name' => 'ERROR',
|
||||
'channel' => 'meh',
|
||||
'context' => array('from' => 'logger'),
|
||||
'context' => ['from' => 'logger'],
|
||||
'datetime' => new \DateTimeImmutable("@0"),
|
||||
'extra' => array('ip' => '127.0.0.1'),
|
||||
'extra' => ['ip' => '127.0.0.1'],
|
||||
'message' => 'log',
|
||||
);
|
||||
];
|
||||
|
||||
$message = $wildfire->format($record);
|
||||
|
||||
@@ -46,15 +46,15 @@ class WildfireFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testFormatWithFileAndLine()
|
||||
{
|
||||
$wildfire = new WildfireFormatter();
|
||||
$record = array(
|
||||
$record = [
|
||||
'level' => Logger::ERROR,
|
||||
'level_name' => 'ERROR',
|
||||
'channel' => 'meh',
|
||||
'context' => array('from' => 'logger'),
|
||||
'context' => ['from' => 'logger'],
|
||||
'datetime' => new \DateTimeImmutable("@0"),
|
||||
'extra' => array('ip' => '127.0.0.1', 'file' => 'test', 'line' => 14),
|
||||
'extra' => ['ip' => '127.0.0.1', 'file' => 'test', 'line' => 14],
|
||||
'message' => 'log',
|
||||
);
|
||||
];
|
||||
|
||||
$message = $wildfire->format($record);
|
||||
|
||||
@@ -71,15 +71,15 @@ class WildfireFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testFormatWithoutContext()
|
||||
{
|
||||
$wildfire = new WildfireFormatter();
|
||||
$record = array(
|
||||
$record = [
|
||||
'level' => Logger::ERROR,
|
||||
'level_name' => 'ERROR',
|
||||
'channel' => 'meh',
|
||||
'context' => array(),
|
||||
'context' => [],
|
||||
'datetime' => new \DateTimeImmutable("@0"),
|
||||
'extra' => array(),
|
||||
'extra' => [],
|
||||
'message' => 'log',
|
||||
);
|
||||
];
|
||||
|
||||
$message = $wildfire->format($record);
|
||||
|
||||
@@ -96,17 +96,17 @@ class WildfireFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testBatchFormatThrowException()
|
||||
{
|
||||
$wildfire = new WildfireFormatter();
|
||||
$record = array(
|
||||
$record = [
|
||||
'level' => Logger::ERROR,
|
||||
'level_name' => 'ERROR',
|
||||
'channel' => 'meh',
|
||||
'context' => array(),
|
||||
'context' => [],
|
||||
'datetime' => new \DateTimeImmutable("@0"),
|
||||
'extra' => array(),
|
||||
'extra' => [],
|
||||
'message' => 'log',
|
||||
);
|
||||
];
|
||||
|
||||
$wildfire->formatBatch(array($record));
|
||||
$wildfire->formatBatch([$record]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,22 +115,22 @@ class WildfireFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testTableFormat()
|
||||
{
|
||||
$wildfire = new WildfireFormatter();
|
||||
$record = array(
|
||||
$record = [
|
||||
'level' => Logger::ERROR,
|
||||
'level_name' => 'ERROR',
|
||||
'channel' => 'table-channel',
|
||||
'context' => array(
|
||||
WildfireFormatter::TABLE => array(
|
||||
array('col1', 'col2', 'col3'),
|
||||
array('val1', 'val2', 'val3'),
|
||||
array('foo1', 'foo2', 'foo3'),
|
||||
array('bar1', 'bar2', 'bar3'),
|
||||
),
|
||||
),
|
||||
'context' => [
|
||||
WildfireFormatter::TABLE => [
|
||||
['col1', 'col2', 'col3'],
|
||||
['val1', 'val2', 'val3'],
|
||||
['foo1', 'foo2', 'foo3'],
|
||||
['bar1', 'bar2', 'bar3'],
|
||||
],
|
||||
],
|
||||
'datetime' => new \DateTimeImmutable("@0"),
|
||||
'extra' => array(),
|
||||
'extra' => [],
|
||||
'message' => 'table-message',
|
||||
);
|
||||
];
|
||||
|
||||
$message = $wildfire->format($record);
|
||||
|
||||
|
Reference in New Issue
Block a user