Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / http-kernel / Tests / DataCollector / LoggerDataCollectorTest.php
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\Component\HttpKernel\Tests\DataCollector;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Debug\Exception\SilencedErrorContext;
16 use Symfony\Component\HttpKernel\DataCollector\LoggerDataCollector;
17 use Symfony\Component\VarDumper\Cloner\Data;
18
19 class LoggerDataCollectorTest extends TestCase
20 {
21     private static $data;
22
23     /**
24      * @dataProvider getCollectTestData
25      */
26     public function testCollect($nb, $logs, $expectedLogs, $expectedDeprecationCount, $expectedScreamCount, $expectedPriorities = null)
27     {
28         $logger = $this->getMockBuilder('Symfony\Component\HttpKernel\Log\DebugLoggerInterface')->getMock();
29         $logger->expects($this->once())->method('countErrors')->will($this->returnValue($nb));
30         $logger->expects($this->exactly(2))->method('getLogs')->will($this->returnValue($logs));
31
32         // disable cloning the context, to ease fixtures creation.
33         $c = $this->getMockBuilder(LoggerDataCollector::class)
34             ->setMethods(array('cloneVar'))
35             ->setConstructorArgs(array($logger))
36             ->getMock();
37         $c->expects($this->any())->method('cloneVar')->willReturn(self::$data);
38         $c->lateCollect();
39
40         $this->assertEquals('logger', $c->getName());
41         $this->assertEquals($nb, $c->countErrors());
42         $this->assertEquals($expectedLogs, $c->getLogs());
43         $this->assertEquals($expectedDeprecationCount, $c->countDeprecations());
44         $this->assertEquals($expectedScreamCount, $c->countScreams());
45
46         if (isset($expectedPriorities)) {
47             $this->assertSame($expectedPriorities, $c->getPriorities());
48         }
49     }
50
51     public function getCollectTestData()
52     {
53         if (null === self::$data) {
54             self::$data = new Data(array());
55         }
56
57         yield 'simple log' => array(
58             1,
59             array(array('message' => 'foo', 'context' => array(), 'priority' => 100, 'priorityName' => 'DEBUG')),
60             array(array('message' => 'foo', 'context' => array(), 'priority' => 100, 'priorityName' => 'DEBUG')),
61             0,
62             0,
63         );
64
65         yield 'log with a context' => array(
66             1,
67             array(array('message' => 'foo', 'context' => array('foo' => 'bar'), 'priority' => 100, 'priorityName' => 'DEBUG')),
68             array(array('message' => 'foo', 'context' => self::$data, 'priority' => 100, 'priorityName' => 'DEBUG')),
69             0,
70             0,
71         );
72
73         if (!class_exists(SilencedErrorContext::class)) {
74             return;
75         }
76
77         yield 'logs with some deprecations' => array(
78             1,
79             array(
80                 array('message' => 'foo3', 'context' => array('exception' => new \ErrorException('warning', 0, E_USER_WARNING)), 'priority' => 100, 'priorityName' => 'DEBUG'),
81                 array('message' => 'foo', 'context' => array('exception' => new \ErrorException('deprecated', 0, E_DEPRECATED)), 'priority' => 100, 'priorityName' => 'DEBUG'),
82                 array('message' => 'foo2', 'context' => array('exception' => new \ErrorException('deprecated', 0, E_USER_DEPRECATED)), 'priority' => 100, 'priorityName' => 'DEBUG'),
83             ),
84             array(
85                 array('message' => 'foo3', 'context' => self::$data, 'priority' => 100, 'priorityName' => 'DEBUG'),
86                 array('message' => 'foo', 'context' => self::$data, 'priority' => 100, 'priorityName' => 'DEBUG', 'errorCount' => 1, 'scream' => false),
87                 array('message' => 'foo2', 'context' => self::$data, 'priority' => 100, 'priorityName' => 'DEBUG', 'errorCount' => 1, 'scream' => false),
88             ),
89             2,
90             0,
91             array(100 => array('count' => 3, 'name' => 'DEBUG')),
92         );
93
94         yield 'logs with some silent errors' => array(
95             1,
96             array(
97                 array('message' => 'foo3', 'context' => array('exception' => new \ErrorException('warning', 0, E_USER_WARNING)), 'priority' => 100, 'priorityName' => 'DEBUG'),
98                 array('message' => 'foo3', 'context' => array('exception' => new SilencedErrorContext(E_USER_WARNING, __FILE__, __LINE__)), 'priority' => 100, 'priorityName' => 'DEBUG'),
99             ),
100             array(
101                 array('message' => 'foo3', 'context' => self::$data, 'priority' => 100, 'priorityName' => 'DEBUG'),
102                 array('message' => 'foo3', 'context' => self::$data, 'priority' => 100, 'priorityName' => 'DEBUG', 'errorCount' => 1, 'scream' => true),
103             ),
104             0,
105             1,
106         );
107     }
108 }