|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Bridge\Monolog\Tests\Formatter; |
| 13 | + |
| 14 | +use Monolog\Logger; |
| 15 | +use PHPUnit\Framework\TestCase; |
| 16 | +use Symfony\Bridge\Monolog\Formatter\ConsoleFormatter; |
| 17 | + |
| 18 | +class ConsoleFormatterTest extends TestCase |
| 19 | +{ |
| 20 | + /** |
| 21 | + * @dataProvider providerFormatTests |
| 22 | + */ |
| 23 | + public function testFormat(array $record, $expectedMessage) |
| 24 | + { |
| 25 | + $formatter = new ConsoleFormatter(); |
| 26 | + self::assertSame($expectedMessage, $formatter->format($record)); |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * @return array |
| 31 | + */ |
| 32 | + public function providerFormatTests() |
| 33 | + { |
| 34 | + $currentDateTime = new \DateTime(); |
| 35 | + |
| 36 | + return [ |
| 37 | + 'record with DateTime object in datetime field' => [ |
| 38 | + 'record' => [ |
| 39 | + 'message' => 'test', |
| 40 | + 'context' => [], |
| 41 | + 'level' => Logger::WARNING, |
| 42 | + 'level_name' => Logger::getLevelName(Logger::WARNING), |
| 43 | + 'channel' => 'test', |
| 44 | + 'datetime' => $currentDateTime, |
| 45 | + 'extra' => [], |
| 46 | + ], |
| 47 | + 'expectedMessage' => sprintf( |
| 48 | + "%s <fg=cyan>WARNING </> <comment>[test]</> test\n", |
| 49 | + $currentDateTime->format(ConsoleFormatter::SIMPLE_DATE) |
| 50 | + ), |
| 51 | + ], |
| 52 | + 'record with string in datetime field' => [ |
| 53 | + 'record' => [ |
| 54 | + 'message' => 'test', |
| 55 | + 'context' => [], |
| 56 | + 'level' => Logger::WARNING, |
| 57 | + 'level_name' => Logger::getLevelName(Logger::WARNING), |
| 58 | + 'channel' => 'test', |
| 59 | + 'datetime' => '2019-01-01T00:42:00+00:00', |
| 60 | + 'extra' => [], |
| 61 | + ], |
| 62 | + 'expectedMessage' => "2019-01-01T00:42:00+00:00 <fg=cyan>WARNING </> <comment>[test]</> test\n", |
| 63 | + ], |
| 64 | + ]; |
| 65 | + } |
| 66 | +} |
0 commit comments