11
11
12
12
namespace Symfony \Component \HttpKernel \Tests \DataCollector ;
13
13
14
+ use Symfony \Component \Debug \Exception \SilencedErrorContext ;
14
15
use Symfony \Component \HttpKernel \DataCollector \LoggerDataCollector ;
15
16
16
17
class LoggerDataCollectorTest extends \PHPUnit_Framework_TestCase
@@ -27,11 +28,18 @@ public function testCollect($nb, $logs, $expectedLogs, $expectedDeprecationCount
27
28
$ c = new LoggerDataCollector ($ logger );
28
29
$ c ->lateCollect ();
29
30
30
- $ this ->assertSame ('logger ' , $ c ->getName ());
31
- $ this ->assertSame ($ nb , $ c ->countErrors ());
32
- $ this ->assertSame ($ expectedLogs ?: $ logs , $ c ->getLogs ());
33
- $ this ->assertSame ($ expectedDeprecationCount , $ c ->countDeprecations ());
34
- $ this ->assertSame ($ expectedScreamCount , $ c ->countScreams ());
31
+ // Remove the trace from the real logs, to ease fixtures creation.
32
+ $ logs = array_map (function ($ log ) {
33
+ unset($ log ['context ' ]['trace ' ], $ log ['context ' ]['exception ' ]['trace ' ]);
34
+
35
+ return $ log ;
36
+ }, $ c ->getLogs ());
37
+
38
+ $ this ->assertEquals ('logger ' , $ c ->getName ());
39
+ $ this ->assertEquals ($ nb , $ c ->countErrors ());
40
+ $ this ->assertEquals ($ expectedLogs , $ logs );
41
+ $ this ->assertEquals ($ expectedDeprecationCount , $ c ->countDeprecations ());
42
+ $ this ->assertEquals ($ expectedScreamCount , $ c ->countScreams ());
35
43
36
44
if (isset ($ expectedPriorities )) {
37
45
$ this ->assertSame ($ expectedPriorities , $ c ->getPriorities ());
@@ -40,56 +48,63 @@ public function testCollect($nb, $logs, $expectedLogs, $expectedDeprecationCount
40
48
41
49
public function getCollectTestData ()
42
50
{
43
- return array (
44
- array (
45
- 1 ,
46
- array (array ('message ' => 'foo ' , 'context ' => array (), 'priority ' => 100 , 'priorityName ' => 'DEBUG ' )),
47
- null ,
48
- 0 ,
49
- 0 ,
50
- ),
51
- array (
52
- 1 ,
53
- array (array ('message ' => 'foo ' , 'context ' => array ('foo ' => fopen (__FILE__ , 'r ' )), 'priority ' => 100 , 'priorityName ' => 'DEBUG ' )),
54
- array (array ('message ' => 'foo ' , 'context ' => array ('foo ' => 'Resource(stream) ' ), 'priority ' => 100 , 'priorityName ' => 'DEBUG ' )),
55
- 0 ,
56
- 0 ,
57
- ),
51
+ yield 'simple log ' => array (
52
+ 1 ,
53
+ array (array ('message ' => 'foo ' , 'context ' => array (), 'priority ' => 100 , 'priorityName ' => 'DEBUG ' )),
54
+ array (array ('message ' => 'foo ' , 'context ' => array (), 'priority ' => 100 , 'priorityName ' => 'DEBUG ' )),
55
+ 0 ,
56
+ 0 ,
57
+ );
58
+
59
+ yield 'log with a resource ' => array (
60
+ 1 ,
61
+ array (array ('message ' => 'foo ' , 'context ' => array ('foo ' => fopen (__FILE__ , 'r ' )), 'priority ' => 100 , 'priorityName ' => 'DEBUG ' )),
62
+ array (array ('message ' => 'foo ' , 'context ' => array ('foo ' => 'Resource(stream) ' ), 'priority ' => 100 , 'priorityName ' => 'DEBUG ' )),
63
+ 0 ,
64
+ 0 ,
65
+ );
66
+
67
+ yield 'log with an object ' => array (
68
+ 1 ,
69
+ array (array ('message ' => 'foo ' , 'context ' => array ('foo ' => new \stdClass ()), 'priority ' => 100 , 'priorityName ' => 'DEBUG ' )),
70
+ array (array ('message ' => 'foo ' , 'context ' => array ('foo ' => 'Object(stdClass) ' ), 'priority ' => 100 , 'priorityName ' => 'DEBUG ' )),
71
+ 0 ,
72
+ 0 ,
73
+ );
74
+
75
+ if (!class_exists (SilencedErrorContext::class)) {
76
+ return ;
77
+ }
78
+
79
+ yield 'logs with some deprecations ' => array (
80
+ 1 ,
58
81
array (
59
- 1 ,
60
- array (array ('message ' => 'foo ' , 'context ' => array ('foo ' => new \stdClass ()), 'priority ' => 100 , 'priorityName ' => 'DEBUG ' )),
61
- array (array ('message ' => 'foo ' , 'context ' => array ('foo ' => 'Object(stdClass) ' ), 'priority ' => 100 , 'priorityName ' => 'DEBUG ' )),
62
- 0 ,
63
- 0 ,
82
+ array ('message ' => 'foo3 ' , 'context ' => array ('exception ' => new \ErrorException ('warning ' , 0 , E_USER_WARNING )), 'priority ' => 100 , 'priorityName ' => 'DEBUG ' ),
83
+ array ('message ' => 'foo ' , 'context ' => array ('exception ' => new \ErrorException ('deprecated ' , 0 , E_DEPRECATED )), 'priority ' => 100 , 'priorityName ' => 'DEBUG ' ),
84
+ array ('message ' => 'foo2 ' , 'context ' => array ('exception ' => new \ErrorException ('deprecated ' , 0 , E_USER_DEPRECATED )), 'priority ' => 100 , 'priorityName ' => 'DEBUG ' ),
64
85
),
65
86
array (
66
- 1 ,
67
- array (
68
- array ('message ' => 'foo ' , 'context ' => array ('type ' => E_DEPRECATED , 'level ' => E_ALL ), 'priority ' => 100 , 'priorityName ' => 'DEBUG ' ),
69
- array ('message ' => 'foo2 ' , 'context ' => array ('type ' => E_USER_DEPRECATED , 'level ' => E_ALL ), 'priority ' => 100 , 'priorityName ' => 'DEBUG ' ),
70
- ),
71
- null ,
72
- 2 ,
73
- 0 ,
74
- array (100 => array ('count ' => 2 , 'name ' => 'DEBUG ' )),
87
+ array ('message ' => 'foo3 ' , 'context ' => array ('exception ' => array ('file ' => __FILE__ , 'line ' => 82 , 'class ' => \ErrorException::class, 'message ' => 'warning ' )), 'priority ' => 100 , 'priorityName ' => 'DEBUG ' ),
88
+ array ('message ' => 'foo ' , 'context ' => array ('type ' => 'E_DEPRECATED ' , 'file ' => __FILE__ , 'line ' => 83 , 'errorCount ' => 1 , 'scream ' => false ), 'priority ' => 100 , 'priorityName ' => 'DEBUG ' ),
89
+ array ('message ' => 'foo2 ' , 'context ' => array ('type ' => 'E_USER_DEPRECATED ' , 'file ' => __FILE__ , 'line ' => 84 , 'errorCount ' => 1 , 'scream ' => false ), 'priority ' => 100 , 'priorityName ' => 'DEBUG ' ),
75
90
),
91
+ 2 ,
92
+ 0 ,
93
+ array (100 => array ('count ' => 3 , 'name ' => 'DEBUG ' )),
94
+ );
95
+
96
+ yield 'logs with some silent errors ' => array (
97
+ 1 ,
76
98
array (
77
- 1 ,
78
- array (array ('message ' => 'foo3 ' , 'context ' => array ('name ' => 'E_USER_WARNING ' , 'type ' => E_USER_WARNING , 'level ' => 0 , 'file ' => __FILE__ , 'line ' => 123 ), 'priority ' => 100 , 'priorityName ' => 'DEBUG ' )),
79
- 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 ' )),
80
- 0 ,
81
- 1 ,
99
+ array ('message ' => 'foo3 ' , 'context ' => array ('exception ' => new \ErrorException ('warning ' , 0 , E_USER_WARNING )), 'priority ' => 100 , 'priorityName ' => 'DEBUG ' ),
100
+ array ('message ' => 'foo3 ' , 'context ' => array ('exception ' => new SilencedErrorContext (E_USER_WARNING , __FILE__ , __LINE__ )), 'priority ' => 100 , 'priorityName ' => 'DEBUG ' ),
82
101
),
83
102
array (
84
- 1 ,
85
- array (
86
- array ('message ' => 'foo3 ' , 'context ' => array ('type ' => E_USER_WARNING , 'level ' => 0 , 'file ' => __FILE__ , 'line ' => 123 ), 'priority ' => 100 , 'priorityName ' => 'DEBUG ' ),
87
- array ('message ' => 'foo3 ' , 'context ' => array ('type ' => E_USER_WARNING , 'level ' => -1 , 'file ' => __FILE__ , 'line ' => 123 ), 'priority ' => 100 , 'priorityName ' => 'DEBUG ' ),
88
- ),
89
- 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 ' )),
90
- 0 ,
91
- 1 ,
103
+ array ('message ' => 'foo3 ' , 'context ' => array ('exception ' => array ('file ' => __FILE__ , 'line ' => 99 , 'class ' => \ErrorException::class, 'message ' => 'warning ' )), 'priority ' => 100 , 'priorityName ' => 'DEBUG ' ),
104
+ array ('message ' => 'foo3 ' , 'context ' => array ('type ' => 'E_USER_WARNING ' , 'file ' => __FILE__ , 'line ' => 100 , 'errorCount ' => 1 , 'scream ' => true ), 'priority ' => 100 , 'priorityName ' => 'DEBUG ' ),
92
105
),
106
+ 0 ,
107
+ 1 ,
93
108
);
94
109
}
95
110
}
0 commit comments