|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 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\Processor; |
| 13 | + |
| 14 | +use Monolog\Logger; |
| 15 | +use PHPUnit\Framework\TestCase; |
| 16 | +use Symfony\Bridge\Monolog\Processor\DebugProcessor; |
| 17 | + |
| 18 | +class DebugProcessorTest extends TestCase |
| 19 | +{ |
| 20 | + /** |
| 21 | + * @dataProvider providerDatetimeFormatTests |
| 22 | + */ |
| 23 | + public function testDatetimeFormat(array $record, $expectedTimestamp) |
| 24 | + { |
| 25 | + $processor = new DebugProcessor(); |
| 26 | + $processor($record); |
| 27 | + |
| 28 | + $records = $processor->getLogs(); |
| 29 | + self::assertCount(1, $records); |
| 30 | + self::assertSame($expectedTimestamp, $records[0]['timestamp']); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * @return array |
| 35 | + */ |
| 36 | + public function providerDatetimeFormatTests() |
| 37 | + { |
| 38 | + $record = $this->getRecord(); |
| 39 | + |
| 40 | + return [ |
| 41 | + [array_merge($record, ['datetime' => new \DateTime('2019-01-01T00:01:00+00:00')]), 1546300860], |
| 42 | + [array_merge($record, ['datetime' => '2019-01-01T00:01:00+00:00']), 1546300860], |
| 43 | + [array_merge($record, ['datetime' => 'foo']), false], |
| 44 | + ]; |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * @return array |
| 49 | + */ |
| 50 | + private function getRecord() |
| 51 | + { |
| 52 | + return [ |
| 53 | + 'message' => 'test', |
| 54 | + 'context' => [], |
| 55 | + 'level' => Logger::DEBUG, |
| 56 | + 'level_name' => Logger::getLevelName(Logger::DEBUG), |
| 57 | + 'channel' => 'test', |
| 58 | + 'datetime' => new \DateTime(), |
| 59 | + ]; |
| 60 | + } |
| 61 | +} |
0 commit comments