Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #34601 [MonologBridge] Fix debug processor datetime type (mRoca)
This PR was merged into the 3.4 branch. Discussion ---------- [MonologBridge] Fix debug processor datetime type | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets |n/a | License | MIT | Doc PR | n/a This PR fixes an eventual `Call to a member function getTimestamp() on string` if any Processor transforms the `datetime` value, and uses the same record conditions as in the [ConsoleFormatter](https://github.com/symfony/monolog-bridge/blob/master/Formatter/ConsoleFormatter.php#L118 ) Commits ------- ffe3f10 [MonologBridge] Fix debug processor datetime type
- Loading branch information
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/Symfony/Bridge/Monolog/Tests/Processor/DebugProcessorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bridge\Monolog\Tests\Processor; | ||
|
||
use Monolog\Logger; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Bridge\Monolog\Processor\DebugProcessor; | ||
|
||
class DebugProcessorTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider providerDatetimeFormatTests | ||
*/ | ||
public function testDatetimeFormat(array $record, $expectedTimestamp) | ||
{ | ||
$processor = new DebugProcessor(); | ||
$processor($record); | ||
|
||
$records = $processor->getLogs(); | ||
self::assertCount(1, $records); | ||
self::assertSame($expectedTimestamp, $records[0]['timestamp']); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function providerDatetimeFormatTests() | ||
{ | ||
$record = $this->getRecord(); | ||
|
||
return [ | ||
[array_merge($record, ['datetime' => new \DateTime('2019-01-01T00:01:00+00:00')]), 1546300860], | ||
[array_merge($record, ['datetime' => '2019-01-01T00:01:00+00:00']), 1546300860], | ||
[array_merge($record, ['datetime' => 'foo']), false], | ||
]; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
private function getRecord() | ||
{ | ||
return [ | ||
'message' => 'test', | ||
'context' => [], | ||
'level' => Logger::DEBUG, | ||
'level_name' => Logger::getLevelName(Logger::DEBUG), | ||
'channel' => 'test', | ||
'datetime' => new \DateTime(), | ||
]; | ||
} | ||
} |