7
7
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
8
8
*/
9
9
10
- namespace PHP_CodeSniffer \Tests \Core \Util \MsgCollector ;
10
+ namespace PHP_CodeSniffer \Tests \Core \Util \MessageCollector ;
11
11
12
- use PHP_CodeSniffer \Util \MsgCollector ;
12
+ use PHP_CodeSniffer \Util \MessageCollector ;
13
13
use PHPUnit \Framework \TestCase ;
14
14
15
15
/**
16
16
* Tests the message caching and display functionality.
17
17
*
18
- * @covers \PHP_CodeSniffer\Util\MsgCollector
18
+ * @covers \PHP_CodeSniffer\Util\MessageCollector
19
19
*/
20
- final class MsgCollectorTest extends TestCase
20
+ final class MessageCollectorTest extends TestCase
21
21
{
22
22
23
23
@@ -43,7 +43,7 @@ public function testAddingNonStringMessageResultsInException($message)
43
43
$ this ->setExpectedException ($ exception , $ exceptionMsg );
44
44
}
45
45
46
- $ msgCollector = new MsgCollector ();
46
+ $ msgCollector = new MessageCollector ();
47
47
$ msgCollector ->add ($ message );
48
48
49
49
}//end testAddingNonStringMessageResultsInException()
@@ -80,7 +80,7 @@ public function dataAddingNonStringMessageResultsInException()
80
80
public function testAddingMessageWithUnsupportedMessageTypeResultsInException ($ type )
81
81
{
82
82
$ exception = 'InvalidArgumentException ' ;
83
- $ exceptionMsg = 'The message $type should be one of the predefined MsgCollector constants. Received: ' ;
83
+ $ exceptionMsg = 'The message $type should be one of the predefined MessageCollector constants. Received: ' ;
84
84
if (method_exists ($ this , 'expectException ' ) === true ) {
85
85
// PHPUnit 5+.
86
86
$ this ->expectException ($ exception );
@@ -90,7 +90,7 @@ public function testAddingMessageWithUnsupportedMessageTypeResultsInException($t
90
90
$ this ->setExpectedException ($ exception , $ exceptionMsg );
91
91
}
92
92
93
- $ msgCollector = new MsgCollector ();
93
+ $ msgCollector = new MessageCollector ();
94
94
$ msgCollector ->add ('Message ' , $ type );
95
95
96
96
}//end testAddingMessageWithUnsupportedMessageTypeResultsInException()
@@ -135,7 +135,7 @@ public function dataAddingMessageWithUnsupportedMessageTypeResultsInException()
135
135
*/
136
136
public function testContainsBlockingErrors ($ messages , $ expected )
137
137
{
138
- $ msgCollector = new MsgCollector ();
138
+ $ msgCollector = new MessageCollector ();
139
139
$ this ->createErrorCache ($ msgCollector , $ messages );
140
140
141
141
$ this ->assertSame ($ expected , $ msgCollector ->containsBlockingErrors ());
@@ -159,25 +159,25 @@ public function dataContainsBlockingErrors()
159
159
],
160
160
'Only non-blocking messages ' => [
161
161
'messages ' => [
162
- 'First message ' => MsgCollector ::WARNING ,
163
- 'Second message ' => MsgCollector ::NOTICE ,
164
- 'Third message ' => MsgCollector ::DEPRECATED ,
162
+ 'First message ' => MessageCollector ::WARNING ,
163
+ 'Second message ' => MessageCollector ::NOTICE ,
164
+ 'Third message ' => MessageCollector ::DEPRECATED ,
165
165
],
166
166
'expected ' => false ,
167
167
],
168
168
'Only blocking messages ' => [
169
169
'messages ' => [
170
- 'First message ' => MsgCollector ::ERROR ,
171
- 'Second message ' => MsgCollector ::ERROR ,
172
- 'Third message ' => MsgCollector ::ERROR ,
170
+ 'First message ' => MessageCollector ::ERROR ,
171
+ 'Second message ' => MessageCollector ::ERROR ,
172
+ 'Third message ' => MessageCollector ::ERROR ,
173
173
],
174
174
'expected ' => true ,
175
175
],
176
176
'Mix of blocking and non-blocking messages ' => [
177
177
'messages ' => [
178
- 'First message ' => MsgCollector ::DEPRECATED ,
179
- 'Second message ' => MsgCollector ::ERROR ,
180
- 'Third message ' => MsgCollector ::WARNING ,
178
+ 'First message ' => MessageCollector ::DEPRECATED ,
179
+ 'Second message ' => MessageCollector ::ERROR ,
180
+ 'Third message ' => MessageCollector ::WARNING ,
181
181
],
182
182
'expected ' => true ,
183
183
],
@@ -204,7 +204,7 @@ public function dataContainsBlockingErrors()
204
204
*/
205
205
public function testDisplayingNonBlockingMessages ($ messages , $ expected )
206
206
{
207
- $ msgCollector = new MsgCollector ();
207
+ $ msgCollector = new MessageCollector ();
208
208
$ this ->createErrorCache ($ msgCollector , $ messages );
209
209
210
210
$ this ->expectOutputString ($ expected );
@@ -231,54 +231,54 @@ public function dataDisplayingNonBlockingMessages()
231
231
],
232
232
'One warning ' => [
233
233
'messages ' => [
234
- 'This is a warning ' => MsgCollector ::WARNING ,
234
+ 'This is a warning ' => MessageCollector ::WARNING ,
235
235
],
236
236
'expected ' => 'WARNING: This is a warning ' .PHP_EOL .PHP_EOL ,
237
237
],
238
238
'One notice ' => [
239
239
'messages ' => [
240
- 'This is a notice ' => MsgCollector ::NOTICE ,
240
+ 'This is a notice ' => MessageCollector ::NOTICE ,
241
241
],
242
242
'expected ' => 'NOTICE: This is a notice ' .PHP_EOL .PHP_EOL ,
243
243
],
244
244
'One deprecation ' => [
245
245
'messages ' => [
246
- 'This is a deprecation ' => MsgCollector ::DEPRECATED ,
246
+ 'This is a deprecation ' => MessageCollector ::DEPRECATED ,
247
247
],
248
248
'expected ' => 'DEPRECATED: This is a deprecation ' .PHP_EOL .PHP_EOL ,
249
249
],
250
250
'Multiple warnings ' => [
251
251
'messages ' => [
252
- 'First warning ' => MsgCollector ::WARNING ,
253
- 'Second warning ' => MsgCollector ::WARNING ,
252
+ 'First warning ' => MessageCollector ::WARNING ,
253
+ 'Second warning ' => MessageCollector ::WARNING ,
254
254
],
255
255
'expected ' => 'WARNING: First warning ' .PHP_EOL
256
256
.'WARNING: Second warning ' .PHP_EOL .PHP_EOL ,
257
257
],
258
258
'Multiple notices ' => [
259
259
'messages ' => [
260
- 'First notice ' => MsgCollector ::NOTICE ,
261
- 'Second notice ' => MsgCollector ::NOTICE ,
262
- 'Third notice ' => MsgCollector ::NOTICE ,
260
+ 'First notice ' => MessageCollector ::NOTICE ,
261
+ 'Second notice ' => MessageCollector ::NOTICE ,
262
+ 'Third notice ' => MessageCollector ::NOTICE ,
263
263
],
264
264
'expected ' => 'NOTICE: First notice ' .PHP_EOL
265
265
.'NOTICE: Second notice ' .PHP_EOL
266
266
.'NOTICE: Third notice ' .PHP_EOL .PHP_EOL ,
267
267
],
268
268
'Multiple deprecations ' => [
269
269
'messages ' => [
270
- 'First deprecation ' => MsgCollector ::DEPRECATED ,
271
- 'Second deprecation ' => MsgCollector ::DEPRECATED ,
270
+ 'First deprecation ' => MessageCollector ::DEPRECATED ,
271
+ 'Second deprecation ' => MessageCollector ::DEPRECATED ,
272
272
],
273
273
'expected ' => 'DEPRECATED: First deprecation ' .PHP_EOL
274
274
.'DEPRECATED: Second deprecation ' .PHP_EOL .PHP_EOL ,
275
275
],
276
276
'All together now ' => [
277
277
'messages ' => [
278
- 'First deprecation ' => MsgCollector ::DEPRECATED ,
279
- 'Second warning ' => MsgCollector ::WARNING ,
280
- 'Third notice ' => MsgCollector ::NOTICE ,
281
- 'Fourth warning ' => MsgCollector ::WARNING ,
278
+ 'First deprecation ' => MessageCollector ::DEPRECATED ,
279
+ 'Second warning ' => MessageCollector ::WARNING ,
280
+ 'Third notice ' => MessageCollector ::NOTICE ,
281
+ 'Fourth warning ' => MessageCollector ::WARNING ,
282
282
],
283
283
'expected ' => 'WARNING: Second warning ' .PHP_EOL
284
284
.'WARNING: Fourth warning ' .PHP_EOL
@@ -319,7 +319,7 @@ public function testDisplayingBlockingErrors($messages, $expected)
319
319
$ this ->setExpectedException ($ exception , $ expected );
320
320
}
321
321
322
- $ msgCollector = new MsgCollector ();
322
+ $ msgCollector = new MessageCollector ();
323
323
$ this ->createErrorCache ($ msgCollector , $ messages );
324
324
$ msgCollector ->display ();
325
325
@@ -339,27 +339,27 @@ public function dataDisplayingBlockingErrors()
339
339
return [
340
340
'Single error ' => [
341
341
'messages ' => [
342
- 'This is an error ' => MsgCollector ::ERROR ,
342
+ 'This is an error ' => MessageCollector ::ERROR ,
343
343
],
344
344
'expected ' => 'ERROR: This is an error ' .PHP_EOL .PHP_EOL ,
345
345
],
346
346
'Multiple errors ' => [
347
347
'messages ' => [
348
- 'First error ' => MsgCollector ::ERROR ,
349
- 'Second error ' => MsgCollector ::ERROR ,
348
+ 'First error ' => MessageCollector ::ERROR ,
349
+ 'Second error ' => MessageCollector ::ERROR ,
350
350
],
351
351
'expected ' => 'ERROR: First error ' .PHP_EOL
352
352
.'ERROR: Second error ' .PHP_EOL .PHP_EOL ,
353
353
],
354
354
'Errors mixed with non-blocking messages ' => [
355
355
'messages ' => [
356
- 'First deprecation ' => MsgCollector ::DEPRECATED ,
357
- 'Second warning ' => MsgCollector ::WARNING ,
358
- 'Third notice ' => MsgCollector ::NOTICE ,
359
- 'Fourth error ' => MsgCollector ::ERROR ,
360
- 'Fifth warning ' => MsgCollector ::WARNING ,
361
- 'Sixth error ' => MsgCollector ::ERROR ,
362
- 'Seventh deprecation ' => MsgCollector ::DEPRECATED ,
356
+ 'First deprecation ' => MessageCollector ::DEPRECATED ,
357
+ 'Second warning ' => MessageCollector ::WARNING ,
358
+ 'Third notice ' => MessageCollector ::NOTICE ,
359
+ 'Fourth error ' => MessageCollector ::ERROR ,
360
+ 'Fifth warning ' => MessageCollector ::WARNING ,
361
+ 'Sixth error ' => MessageCollector ::ERROR ,
362
+ 'Seventh deprecation ' => MessageCollector ::DEPRECATED ,
363
363
],
364
364
'expected ' => 'ERROR: Fourth error ' .PHP_EOL
365
365
.'ERROR: Sixth error ' .PHP_EOL
@@ -379,16 +379,16 @@ public function dataDisplayingBlockingErrors()
379
379
* Verify and safeguard that adding the same message twice is accepted when messages have different error levels.
380
380
*
381
381
* Note: have multiple messages with the exact same text is not great for conveying information
382
- * to the end-user, but that's not the concern of the MsgCollector class.
382
+ * to the end-user, but that's not the concern of the MessageCollector class.
383
383
*
384
384
* @return void
385
385
*/
386
386
public function testNonUniqueMessagesWithDifferentErrorLevelAreAccepted ()
387
387
{
388
388
$ message = 'Trying to add the same message twice ' ;
389
- $ msgCollector = new MsgCollector ();
390
- $ msgCollector ->add ($ message , MsgCollector ::NOTICE );
391
- $ msgCollector ->add ($ message , MsgCollector ::WARNING );
389
+ $ msgCollector = new MessageCollector ();
390
+ $ msgCollector ->add ($ message , MessageCollector ::NOTICE );
391
+ $ msgCollector ->add ($ message , MessageCollector ::WARNING );
392
392
393
393
$ expected = 'WARNING: Trying to add the same message twice ' .PHP_EOL ;
394
394
$ expected .= 'NOTICE: Trying to add the same message twice ' .PHP_EOL .PHP_EOL ;
@@ -403,16 +403,16 @@ public function testNonUniqueMessagesWithDifferentErrorLevelAreAccepted()
403
403
* Verify and safeguard that adding the same message twice is accepted when messages have the same error level.
404
404
*
405
405
* Note: have multiple messages with the exact same text is not great for conveying information
406
- * to the end-user, but that's not the concern of the MsgCollector class.
406
+ * to the end-user, but that's not the concern of the MessageCollector class.
407
407
*
408
408
* @return void
409
409
*/
410
410
public function testNonUniqueMessagesWithSameErrorLevelAreAccepted ()
411
411
{
412
412
$ message = 'Trying to add the same message twice ' ;
413
- $ msgCollector = new MsgCollector ();
414
- $ msgCollector ->add ($ message , MsgCollector ::NOTICE );
415
- $ msgCollector ->add ($ message , MsgCollector ::NOTICE );
413
+ $ msgCollector = new MessageCollector ();
414
+ $ msgCollector ->add ($ message , MessageCollector ::NOTICE );
415
+ $ msgCollector ->add ($ message , MessageCollector ::NOTICE );
416
416
417
417
$ expected = 'NOTICE: Trying to add the same message twice ' .PHP_EOL ;
418
418
$ expected .= 'NOTICE: Trying to add the same message twice ' .PHP_EOL .PHP_EOL ;
@@ -431,13 +431,13 @@ public function testNonUniqueMessagesWithSameErrorLevelAreAccepted()
431
431
public function testCallingDisplayTwiceWillNotShowMessagesTwice ()
432
432
{
433
433
$ messages = [
434
- 'First notice ' => MsgCollector ::NOTICE ,
435
- 'Second deprecation ' => MsgCollector ::DEPRECATED ,
436
- 'Third notice ' => MsgCollector ::NOTICE ,
437
- 'Fourth warning ' => MsgCollector ::WARNING ,
434
+ 'First notice ' => MessageCollector ::NOTICE ,
435
+ 'Second deprecation ' => MessageCollector ::DEPRECATED ,
436
+ 'Third notice ' => MessageCollector ::NOTICE ,
437
+ 'Fourth warning ' => MessageCollector ::WARNING ,
438
438
];
439
439
440
- $ msgCollector = new MsgCollector ();
440
+ $ msgCollector = new MessageCollector ();
441
441
$ this ->createErrorCache ($ msgCollector , $ messages );
442
442
443
443
$ expected = 'WARNING: Fourth warning ' .PHP_EOL ;
@@ -465,13 +465,13 @@ public function testCallingDisplayTwiceWillNotShowMessagesTwice()
465
465
public function testDisplayOrderHandling ($ order , $ expected )
466
466
{
467
467
$ messages = [
468
- 'First notice ' => MsgCollector ::NOTICE ,
469
- 'Second deprecation ' => MsgCollector ::DEPRECATED ,
470
- 'Third notice ' => MsgCollector ::NOTICE ,
471
- 'Fourth warning ' => MsgCollector ::WARNING ,
468
+ 'First notice ' => MessageCollector ::NOTICE ,
469
+ 'Second deprecation ' => MessageCollector ::DEPRECATED ,
470
+ 'Third notice ' => MessageCollector ::NOTICE ,
471
+ 'Fourth warning ' => MessageCollector ::WARNING ,
472
472
];
473
473
474
- $ msgCollector = new MsgCollector ();
474
+ $ msgCollector = new MessageCollector ();
475
475
$ this ->createErrorCache ($ msgCollector , $ messages );
476
476
477
477
$ this ->expectOutputString ($ expected );
@@ -502,11 +502,11 @@ public function dataDisplayOrderHandling()
502
502
503
503
return [
504
504
'Order by severity ' => [
505
- 'order ' => MsgCollector ::ORDERBY_SEVERITY ,
505
+ 'order ' => MessageCollector ::ORDERBY_SEVERITY ,
506
506
'expected ' => $ expectedForSeverity ,
507
507
],
508
508
'Order by received ' => [
509
- 'order ' => MsgCollector ::ORDERBY_RECEIVED ,
509
+ 'order ' => MessageCollector ::ORDERBY_RECEIVED ,
510
510
'expected ' => $ expectedForReceived ,
511
511
],
512
512
'Invalid order defaults to severity ' => [
@@ -521,13 +521,13 @@ public function dataDisplayOrderHandling()
521
521
/**
522
522
* Test helper.
523
523
*
524
- * @param \PHP_CodeSniffer\Util\MsgCollector $collector The error cache object.
525
- * @param array<string, int> $messages The error messages to add to the cache.
526
- * Key is the message, value is the error level.
524
+ * @param \PHP_CodeSniffer\Util\MessageCollector $collector The error cache object.
525
+ * @param array<string, int> $messages The error messages to add to the cache.
526
+ * Key is the message, value is the error level.
527
527
*
528
528
* @return void
529
529
*/
530
- private function createErrorCache (MsgCollector $ collector , $ messages )
530
+ private function createErrorCache (MessageCollector $ collector , $ messages )
531
531
{
532
532
foreach ($ messages as $ msg => $ type ) {
533
533
$ collector ->add ($ msg , $ type );
0 commit comments