|
18 | 18 | use Symfony\Component\HttpFoundation\Response;
|
19 | 19 | use Symfony\Component\HttpKernel\DataCollector\LoggerDataCollector;
|
20 | 20 | use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
|
| 21 | +use Symfony\Component\VarDumper\Cloner\Data; |
21 | 22 |
|
22 | 23 | class LoggerDataCollectorTest extends TestCase
|
23 | 24 | {
|
@@ -45,6 +46,52 @@ public function testCollectWithUnexpectedFormat()
|
45 | 46 | ], $compilerLogs['Unknown Compiler Pass']);
|
46 | 47 | }
|
47 | 48 |
|
| 49 | + public function testCollectFromDeprecationsLog() |
| 50 | + { |
| 51 | + $containerPathPrefix = __DIR__.'/'; |
| 52 | + $path = $containerPathPrefix.'Deprecations.log'; |
| 53 | + touch($path); |
| 54 | + file_put_contents($path, serialize([[ |
| 55 | + 'type' => 16384, |
| 56 | + 'message' => 'The "Symfony\Bundle\FrameworkBundle\Controller\Controller" class is deprecated since Symfony 4.2, use Symfony\Bundle\FrameworkBundle\Controller\AbstractController instead.', |
| 57 | + 'file' => '/home/hamza/projet/contrib/sf/vendor/symfony/framework-bundle/Controller/Controller.php', |
| 58 | + 'line' => 17, |
| 59 | + 'trace' => [[ |
| 60 | + 'file' => '/home/hamza/projet/contrib/sf/src/Controller/DefaultController.php', |
| 61 | + 'line' => 9, |
| 62 | + 'function' => 'spl_autoload_call', |
| 63 | + ]], |
| 64 | + 'count' => 1, |
| 65 | + ]])); |
| 66 | + |
| 67 | + $logger = $this |
| 68 | + ->getMockBuilder(DebugLoggerInterface::class) |
| 69 | + ->setMethods(['countErrors', 'getLogs', 'clear']) |
| 70 | + ->getMock(); |
| 71 | + |
| 72 | + $logger->expects($this->once())->method('countErrors')->willReturn(0); |
| 73 | + $logger->expects($this->exactly(2))->method('getLogs')->willReturn([]); |
| 74 | + |
| 75 | + $c = new LoggerDataCollector($logger, $containerPathPrefix); |
| 76 | + $c->lateCollect(); |
| 77 | + |
| 78 | + $processedLogs = $c->getProcessedLogs(); |
| 79 | + |
| 80 | + $this->assertCount(1, $processedLogs); |
| 81 | + |
| 82 | + $this->assertEquals($processedLogs[0]['type'], 'deprecation'); |
| 83 | + $this->assertEquals($processedLogs[0]['errorCounter'], 1); |
| 84 | + $this->assertEquals($processedLogs[0]['timestamp'], (new \DateTimeImmutable())->setTimestamp(filemtime($path))->format(\DateTimeInterface::RFC3339_EXTENDED)); |
| 85 | + $this->assertEquals($processedLogs[0]['priority'], 100); |
| 86 | + $this->assertEquals($processedLogs[0]['priorityName'], 'DEBUG'); |
| 87 | + $this->assertNull($processedLogs[0]['channel']); |
| 88 | + |
| 89 | + $this->assertInstanceOf(Data::class, $processedLogs[0]['message']); |
| 90 | + $this->assertInstanceOf(Data::class, $processedLogs[0]['context']); |
| 91 | + |
| 92 | + @unlink($path); |
| 93 | + } |
| 94 | + |
48 | 95 | public function testWithMainRequest()
|
49 | 96 | {
|
50 | 97 | $mainRequest = new Request();
|
|
0 commit comments