77 * @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
88 */
99
10- namespace PHP_CodeSniffer \Tests \Core \Util \MsgCollector ;
10+ namespace PHP_CodeSniffer \Tests \Core \Util \MessageCollector ;
1111
12- use PHP_CodeSniffer \Util \MsgCollector ;
12+ use PHP_CodeSniffer \Util \MessageCollector ;
1313use PHPUnit \Framework \TestCase ;
1414
1515/**
1616 * Tests the message caching and display functionality.
1717 *
18- * @covers \PHP_CodeSniffer\Util\MsgCollector
18+ * @covers \PHP_CodeSniffer\Util\MessageCollector
1919 */
20- final class MsgCollectorTest extends TestCase
20+ final class MessageCollectorTest extends TestCase
2121{
2222
2323
@@ -43,7 +43,7 @@ public function testAddingNonStringMessageResultsInException($message)
4343 $ this ->setExpectedException ($ exception , $ exceptionMsg );
4444 }
4545
46- $ msgCollector = new MsgCollector ();
46+ $ msgCollector = new MessageCollector ();
4747 $ msgCollector ->add ($ message );
4848
4949 }//end testAddingNonStringMessageResultsInException()
@@ -80,7 +80,7 @@ public function dataAddingNonStringMessageResultsInException()
8080 public function testAddingMessageWithUnsupportedMessageTypeResultsInException ($ type )
8181 {
8282 $ 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: ' ;
8484 if (method_exists ($ this , 'expectException ' ) === true ) {
8585 // PHPUnit 5+.
8686 $ this ->expectException ($ exception );
@@ -90,7 +90,7 @@ public function testAddingMessageWithUnsupportedMessageTypeResultsInException($t
9090 $ this ->setExpectedException ($ exception , $ exceptionMsg );
9191 }
9292
93- $ msgCollector = new MsgCollector ();
93+ $ msgCollector = new MessageCollector ();
9494 $ msgCollector ->add ('Message ' , $ type );
9595
9696 }//end testAddingMessageWithUnsupportedMessageTypeResultsInException()
@@ -135,7 +135,7 @@ public function dataAddingMessageWithUnsupportedMessageTypeResultsInException()
135135 */
136136 public function testContainsBlockingErrors ($ messages , $ expected )
137137 {
138- $ msgCollector = new MsgCollector ();
138+ $ msgCollector = new MessageCollector ();
139139 $ this ->createErrorCache ($ msgCollector , $ messages );
140140
141141 $ this ->assertSame ($ expected , $ msgCollector ->containsBlockingErrors ());
@@ -159,25 +159,25 @@ public function dataContainsBlockingErrors()
159159 ],
160160 'Only non-blocking messages ' => [
161161 '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 ,
165165 ],
166166 'expected ' => false ,
167167 ],
168168 'Only blocking messages ' => [
169169 '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 ,
173173 ],
174174 'expected ' => true ,
175175 ],
176176 'Mix of blocking and non-blocking messages ' => [
177177 '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 ,
181181 ],
182182 'expected ' => true ,
183183 ],
@@ -204,7 +204,7 @@ public function dataContainsBlockingErrors()
204204 */
205205 public function testDisplayingNonBlockingMessages ($ messages , $ expected )
206206 {
207- $ msgCollector = new MsgCollector ();
207+ $ msgCollector = new MessageCollector ();
208208 $ this ->createErrorCache ($ msgCollector , $ messages );
209209
210210 $ this ->expectOutputString ($ expected );
@@ -231,54 +231,54 @@ public function dataDisplayingNonBlockingMessages()
231231 ],
232232 'One warning ' => [
233233 'messages ' => [
234- 'This is a warning ' => MsgCollector ::WARNING ,
234+ 'This is a warning ' => MessageCollector ::WARNING ,
235235 ],
236236 'expected ' => 'WARNING: This is a warning ' .PHP_EOL .PHP_EOL ,
237237 ],
238238 'One notice ' => [
239239 'messages ' => [
240- 'This is a notice ' => MsgCollector ::NOTICE ,
240+ 'This is a notice ' => MessageCollector ::NOTICE ,
241241 ],
242242 'expected ' => 'NOTICE: This is a notice ' .PHP_EOL .PHP_EOL ,
243243 ],
244244 'One deprecation ' => [
245245 'messages ' => [
246- 'This is a deprecation ' => MsgCollector ::DEPRECATED ,
246+ 'This is a deprecation ' => MessageCollector ::DEPRECATED ,
247247 ],
248248 'expected ' => 'DEPRECATED: This is a deprecation ' .PHP_EOL .PHP_EOL ,
249249 ],
250250 'Multiple warnings ' => [
251251 'messages ' => [
252- 'First warning ' => MsgCollector ::WARNING ,
253- 'Second warning ' => MsgCollector ::WARNING ,
252+ 'First warning ' => MessageCollector ::WARNING ,
253+ 'Second warning ' => MessageCollector ::WARNING ,
254254 ],
255255 'expected ' => 'WARNING: First warning ' .PHP_EOL
256256 .'WARNING: Second warning ' .PHP_EOL .PHP_EOL ,
257257 ],
258258 'Multiple notices ' => [
259259 '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 ,
263263 ],
264264 'expected ' => 'NOTICE: First notice ' .PHP_EOL
265265 .'NOTICE: Second notice ' .PHP_EOL
266266 .'NOTICE: Third notice ' .PHP_EOL .PHP_EOL ,
267267 ],
268268 'Multiple deprecations ' => [
269269 'messages ' => [
270- 'First deprecation ' => MsgCollector ::DEPRECATED ,
271- 'Second deprecation ' => MsgCollector ::DEPRECATED ,
270+ 'First deprecation ' => MessageCollector ::DEPRECATED ,
271+ 'Second deprecation ' => MessageCollector ::DEPRECATED ,
272272 ],
273273 'expected ' => 'DEPRECATED: First deprecation ' .PHP_EOL
274274 .'DEPRECATED: Second deprecation ' .PHP_EOL .PHP_EOL ,
275275 ],
276276 'All together now ' => [
277277 '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 ,
282282 ],
283283 'expected ' => 'WARNING: Second warning ' .PHP_EOL
284284 .'WARNING: Fourth warning ' .PHP_EOL
@@ -319,7 +319,7 @@ public function testDisplayingBlockingErrors($messages, $expected)
319319 $ this ->setExpectedException ($ exception , $ expected );
320320 }
321321
322- $ msgCollector = new MsgCollector ();
322+ $ msgCollector = new MessageCollector ();
323323 $ this ->createErrorCache ($ msgCollector , $ messages );
324324 $ msgCollector ->display ();
325325
@@ -339,27 +339,27 @@ public function dataDisplayingBlockingErrors()
339339 return [
340340 'Single error ' => [
341341 'messages ' => [
342- 'This is an error ' => MsgCollector ::ERROR ,
342+ 'This is an error ' => MessageCollector ::ERROR ,
343343 ],
344344 'expected ' => 'ERROR: This is an error ' .PHP_EOL .PHP_EOL ,
345345 ],
346346 'Multiple errors ' => [
347347 'messages ' => [
348- 'First error ' => MsgCollector ::ERROR ,
349- 'Second error ' => MsgCollector ::ERROR ,
348+ 'First error ' => MessageCollector ::ERROR ,
349+ 'Second error ' => MessageCollector ::ERROR ,
350350 ],
351351 'expected ' => 'ERROR: First error ' .PHP_EOL
352352 .'ERROR: Second error ' .PHP_EOL .PHP_EOL ,
353353 ],
354354 'Errors mixed with non-blocking messages ' => [
355355 '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 ,
363363 ],
364364 'expected ' => 'ERROR: Fourth error ' .PHP_EOL
365365 .'ERROR: Sixth error ' .PHP_EOL
@@ -379,16 +379,16 @@ public function dataDisplayingBlockingErrors()
379379 * Verify and safeguard that adding the same message twice is accepted when messages have different error levels.
380380 *
381381 * 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.
383383 *
384384 * @return void
385385 */
386386 public function testNonUniqueMessagesWithDifferentErrorLevelAreAccepted ()
387387 {
388388 $ 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 );
392392
393393 $ expected = 'WARNING: Trying to add the same message twice ' .PHP_EOL ;
394394 $ expected .= 'NOTICE: Trying to add the same message twice ' .PHP_EOL .PHP_EOL ;
@@ -403,16 +403,16 @@ public function testNonUniqueMessagesWithDifferentErrorLevelAreAccepted()
403403 * Verify and safeguard that adding the same message twice is accepted when messages have the same error level.
404404 *
405405 * 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.
407407 *
408408 * @return void
409409 */
410410 public function testNonUniqueMessagesWithSameErrorLevelAreAccepted ()
411411 {
412412 $ 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 );
416416
417417 $ expected = 'NOTICE: Trying to add the same message twice ' .PHP_EOL ;
418418 $ expected .= 'NOTICE: Trying to add the same message twice ' .PHP_EOL .PHP_EOL ;
@@ -431,13 +431,13 @@ public function testNonUniqueMessagesWithSameErrorLevelAreAccepted()
431431 public function testCallingDisplayTwiceWillNotShowMessagesTwice ()
432432 {
433433 $ 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 ,
438438 ];
439439
440- $ msgCollector = new MsgCollector ();
440+ $ msgCollector = new MessageCollector ();
441441 $ this ->createErrorCache ($ msgCollector , $ messages );
442442
443443 $ expected = 'WARNING: Fourth warning ' .PHP_EOL ;
@@ -465,13 +465,13 @@ public function testCallingDisplayTwiceWillNotShowMessagesTwice()
465465 public function testDisplayOrderHandling ($ order , $ expected )
466466 {
467467 $ 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 ,
472472 ];
473473
474- $ msgCollector = new MsgCollector ();
474+ $ msgCollector = new MessageCollector ();
475475 $ this ->createErrorCache ($ msgCollector , $ messages );
476476
477477 $ this ->expectOutputString ($ expected );
@@ -502,11 +502,11 @@ public function dataDisplayOrderHandling()
502502
503503 return [
504504 'Order by severity ' => [
505- 'order ' => MsgCollector ::ORDERBY_SEVERITY ,
505+ 'order ' => MessageCollector ::ORDERBY_SEVERITY ,
506506 'expected ' => $ expectedForSeverity ,
507507 ],
508508 'Order by received ' => [
509- 'order ' => MsgCollector ::ORDERBY_RECEIVED ,
509+ 'order ' => MessageCollector ::ORDERBY_RECEIVED ,
510510 'expected ' => $ expectedForReceived ,
511511 ],
512512 'Invalid order defaults to severity ' => [
@@ -521,13 +521,13 @@ public function dataDisplayOrderHandling()
521521 /**
522522 * Test helper.
523523 *
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.
527527 *
528528 * @return void
529529 */
530- private function createErrorCache (MsgCollector $ collector , $ messages )
530+ private function createErrorCache (MessageCollector $ collector , $ messages )
531531 {
532532 foreach ($ messages as $ msg => $ type ) {
533533 $ collector ->add ($ msg , $ type );
0 commit comments