Yaffs site version 1.1
[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\HttpKernel\DataCollector\LoggerDataCollector;
16
17 class LoggerDataCollectorTest extends TestCase
18 {
19     /**
20      * @dataProvider getCollectTestData
21      */
22     public function testCollect($nb, $logs, $expectedLogs, $expectedDeprecationCount, $expectedScreamCount, $expectedPriorities = null)
23     {
24         $logger = $this->getMockBuilder('Symfony\Component\HttpKernel\Log\DebugLoggerInterface')->getMock();
25         $logger->expects($this->once())->method('countErrors')->will($this->returnValue($nb));
26         $logger->expects($this->exactly(2))->method('getLogs')->will($this->returnValue($logs));
27
28         $c = new LoggerDataCollector($logger);
29         $c->lateCollect();
30
31         $this->assertSame('logger', $c->getName());
32         $this->assertSame($nb, $c->countErrors());
33         $this->assertSame($expectedLogs ?: $logs, $c->getLogs());
34         $this->assertSame($expectedDeprecationCount, $c->countDeprecations());
35         $this->assertSame($expectedScreamCount, $c->countScreams());
36
37         if (isset($expectedPriorities)) {
38             $this->assertSame($expectedPriorities, $c->getPriorities());
39         }
40     }
41
42     public function getCollectTestData()
43     {
44         return array(
45             array(
46                 1,
47                 array(array('message' => 'foo', 'context' => array(), 'priority' => 100, 'priorityName' => 'DEBUG')),
48                 null,
49                 0,
50                 0,
51             ),
52             array(
53                 1,
54                 array(array('message' => 'foo', 'context' => array('foo' => fopen(__FILE__, 'r')), 'priority' => 100, 'priorityName' => 'DEBUG')),
55                 array(array('message' => 'foo', 'context' => array('foo' => 'Resource(stream)'), 'priority' => 100, 'priorityName' => 'DEBUG')),
56                 0,
57                 0,
58             ),
59             array(
60                 1,
61                 array(array('message' => 'foo', 'context' => array('foo' => new \stdClass()), 'priority' => 100, 'priorityName' => 'DEBUG')),
62                 array(array('message' => 'foo', 'context' => array('foo' => 'Object(stdClass)'), 'priority' => 100, 'priorityName' => 'DEBUG')),
63                 0,
64                 0,
65             ),
66             array(
67                 1,
68                 array(
69                     array('message' => 'foo', 'context' => array('type' => E_DEPRECATED, 'level' => E_ALL), 'priority' => 100, 'priorityName' => 'DEBUG'),
70                     array('message' => 'foo2', 'context' => array('type' => E_USER_DEPRECATED, 'level' => E_ALL), 'priority' => 100, 'priorityName' => 'DEBUG'),
71                 ),
72                 null,
73                 2,
74                 0,
75                 array(100 => array('count' => 2, 'name' => 'DEBUG')),
76             ),
77             array(
78                 1,
79                 array(array('message' => 'foo3', 'context' => array('name' => 'E_USER_WARNING', 'type' => E_USER_WARNING, 'level' => 0, 'file' => __FILE__, 'line' => 123), 'priority' => 100, 'priorityName' => 'DEBUG')),
80                 array(array('message' => 'foo3', 'context' => array('name' => 'E_USER_WARNING', 'type' => E_USER_WARNING, 'level' => 0, 'file' => __FILE__, 'line' => 123, 'scream' => true), 'priority' => 100, 'priorityName' => 'DEBUG')),
81                 0,
82                 1,
83             ),
84             array(
85                 1,
86                 array(
87                     array('message' => 'foo3', 'context' => array('type' => E_USER_WARNING, 'level' => 0, 'file' => __FILE__, 'line' => 123), 'priority' => 100, 'priorityName' => 'DEBUG'),
88                     array('message' => 'foo3', 'context' => array('type' => E_USER_WARNING, 'level' => -1, 'file' => __FILE__, 'line' => 123), 'priority' => 100, 'priorityName' => 'DEBUG'),
89                 ),
90                 array(array('message' => 'foo3', 'context' => array('name' => 'E_USER_WARNING', 'type' => E_USER_WARNING, 'level' => -1, 'file' => __FILE__, 'line' => 123, 'errorCount' => 2), 'priority' => 100, 'priorityName' => 'DEBUG')),
91                 0,
92                 1,
93             ),
94         );
95     }
96 }