summaryrefslogtreecommitdiffstats
path: root/tests/Monolog/Formatter/ScalarFormatterTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Monolog/Formatter/ScalarFormatterTest.php')
-rw-r--r--tests/Monolog/Formatter/ScalarFormatterTest.php68
1 files changed, 33 insertions, 35 deletions
diff --git a/tests/Monolog/Formatter/ScalarFormatterTest.php b/tests/Monolog/Formatter/ScalarFormatterTest.php
index b1c8fd4..9af4937 100644
--- a/tests/Monolog/Formatter/ScalarFormatterTest.php
+++ b/tests/Monolog/Formatter/ScalarFormatterTest.php
@@ -1,4 +1,4 @@
-<?php
+<?php declare(strict_types=1);
/*
* This file is part of the Monolog package.
@@ -11,7 +11,9 @@
namespace Monolog\Formatter;
-class ScalarFormatterTest extends \PHPUnit_Framework_TestCase
+use Monolog\DateTimeImmutable;
+
+class ScalarFormatterTest extends \PHPUnit\Framework\TestCase
{
private $formatter;
@@ -22,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'])) {
@@ -37,74 +39,70 @@ class ScalarFormatterTest extends \PHPUnit_Framework_TestCase
public function encodeJson($data)
{
- if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
- return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
- }
-
- return json_encode($data);
+ return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}
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'),
- 'bap' => \DateTime::createFromFormat(\DateTime::ISO8601, '1970-01-01T00:00:00+0000'),
+ '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')),
- 'bap' => '1970-01-01 00:00:00',
- 'ban' => $this->encodeJson(array(
+ 'bam' => $this->encodeJson([1, 2, 3]),
+ 'bat' => $this->encodeJson(['foo' => 'bar']),
+ 'bap' => (string) $dt,
+ '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);
}
}