@@ -73,7 +73,7 @@ public function testAddNotificationWithInvalidParams()
73
73
public function testAddNotificationWithValidTypeAndCallback ()
74
74
{
75
75
$ notificationType = NotificationType::ACTIVATE ;
76
- $ this ->notificationCenterObj ->cleanAllNotifications ();
76
+ $ this ->notificationCenterObj ->clearAllNotificationListeners ();
77
77
78
78
////////////////////////////////////////////////////////////////////////////////////////////////////////////
79
79
// === should add, log and return notification ID when a plain function is passed as an argument === //
@@ -135,7 +135,7 @@ function () {
135
135
136
136
public function testAddNotificationForMultipleNotificationTypes ()
137
137
{
138
- $ this ->notificationCenterObj ->cleanAllNotifications ();
138
+ $ this ->notificationCenterObj ->clearAllNotificationListeners ();
139
139
140
140
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
141
141
// === should add, log and return notification ID when a valid callback is added for each notification type === //
@@ -179,7 +179,7 @@ function () {
179
179
180
180
public function testAddNotificationForMultipleCallbacksForASingleNotificationType ()
181
181
{
182
- $ this ->notificationCenterObj ->cleanAllNotifications ();
182
+ $ this ->notificationCenterObj ->clearAllNotificationListeners ();
183
183
184
184
///////////////////////////////////////////////////////////////////////////////////////
185
185
// === should add, log and return notification ID when multiple valid callbacks
@@ -243,7 +243,7 @@ public function testAddNotificationThatAlreadyAddedCallbackIsNotReAdded()
243
243
244
244
$ functionToSend = function () {
245
245
};
246
- $ this ->notificationCenterObj ->cleanAllNotifications ();
246
+ $ this ->notificationCenterObj ->clearAllNotificationListeners ();
247
247
248
248
///////////////////////////////////////////////////////////////////////////
249
249
// ===== verify that a variable method with same body isn't re-added ===== //
@@ -313,7 +313,7 @@ public function testAddNotificationThatAlreadyAddedCallbackIsNotReAdded()
313
313
314
314
public function testRemoveNotification ()
315
315
{
316
- $ this ->notificationCenterObj ->cleanAllNotifications ();
316
+ $ this ->notificationCenterObj ->clearAllNotificationListeners ();
317
317
318
318
// add a callback for multiple notification types
319
319
$ this ->assertSame (
@@ -407,10 +407,35 @@ function () {
407
407
);
408
408
}
409
409
410
- public function testClearNotifications ()
410
+ public function testclearNotificationsAndVerifyThatclearNotificationListenersWithArgsIsCalled ()
411
+ {
412
+ # Mock NotificationCenter
413
+ $ this ->notificationCenterMock = $ this ->getMockBuilder (NotificationCenter::class)
414
+ ->setConstructorArgs (array ($ this ->loggerMock , $ this ->errorHandlerMock ))
415
+ ->setMethods (array ('clearNotificationListeners ' ))
416
+ ->getMock ();
417
+
418
+ # Log deprecation message
419
+ $ this ->loggerMock ->expects ($ this ->at (0 ))
420
+ ->method ('log ' )
421
+ ->with (
422
+ Logger::WARNING ,
423
+ sprintf ("'clearNotifications' is deprecated. Call 'clearNotificationListeners' instead. " )
424
+ );
425
+
426
+ $ this ->notificationCenterMock ->expects ($ this ->once ())
427
+ ->method ('clearNotificationListeners ' )
428
+ ->with (
429
+ NotificationType::ACTIVATE
430
+ );
431
+
432
+ $ this ->notificationCenterMock ->clearNotifications (NotificationType::ACTIVATE );
433
+ }
434
+
435
+ public function testclearNotificationListeners ()
411
436
{
412
437
// ensure that notifications length is zero for each notification type
413
- $ this ->notificationCenterObj ->cleanAllNotifications ();
438
+ $ this ->notificationCenterObj ->clearAllNotificationListeners ();
414
439
415
440
// add a callback for multiple notification types
416
441
$ this ->notificationCenterObj ->addNotificationListener (
@@ -457,7 +482,7 @@ function () {
457
482
->method ('handleError ' )
458
483
->with (new InvalidNotificationTypeException ('Invalid notification type. ' ));
459
484
460
- $ this ->assertNull ($ this ->notificationCenterObj ->clearNotifications ($ invalid_type ));
485
+ $ this ->assertNull ($ this ->notificationCenterObj ->clearNotificationListeners ($ invalid_type ));
461
486
462
487
// Verify that notifications length for NotificationType::ACTIVATE is still 2
463
488
$ this ->assertSame (
@@ -482,7 +507,7 @@ function () {
482
507
sprintf ("All callbacks for notification type '%s' have been removed. " , NotificationType::ACTIVATE )
483
508
);
484
509
485
- $ this ->notificationCenterObj ->clearNotifications (NotificationType::ACTIVATE );
510
+ $ this ->notificationCenterObj ->clearNotificationListeners (NotificationType::ACTIVATE );
486
511
487
512
// Verify that notifications length for NotificationType::ACTIVATE is now 0
488
513
$ this ->assertSame (
@@ -499,11 +524,11 @@ function () {
499
524
///////////////////////////////////////////////////////////////////////////////////////////////////////////
500
525
// == Verify that no error is thrown when clearNotification is called again for the same notification type === //
501
526
///////////////////////////////////////////////////////////////////////////////////////////////////////////
502
- $ this ->notificationCenterObj ->clearNotifications (NotificationType::ACTIVATE );
527
+ $ this ->notificationCenterObj ->clearNotificationListeners (NotificationType::ACTIVATE );
503
528
}
504
529
505
530
506
- public function testCleanAllNotifications ()
531
+ public function testclearAllNotificationListeners ()
507
532
{
508
533
// using a new notification center object to avoid using the method being tested,
509
534
// to reset notifications list
@@ -558,10 +583,10 @@ function () {
558
583
);
559
584
560
585
////////////////////////////////////////////////////////////////////////////////////////////////////
561
- // === verify that cleanAllNotifications removes all notifications for each notification type === //
586
+ // === verify that clearAllNotificationListeners removes all notifications for each notification type === //
562
587
////////////////////////////////////////////////////////////////////////////////////////////////////
563
588
564
- $ notificationCenterA ->cleanAllNotifications ();
589
+ $ notificationCenterA ->clearAllNotificationListeners ();
565
590
566
591
// verify that notifications length for each type is now set to 0
567
592
$ this ->assertSame (
@@ -574,15 +599,37 @@ function () {
574
599
);
575
600
576
601
///////////////////////////////////////////////////////////////////////////////////////
577
- //=== verify that cleanAllNotifications doesn't throw an error when called again === //
602
+ //=== verify that clearAllNotificationListeners doesn't throw an error when called again === //
578
603
///////////////////////////////////////////////////////////////////////////////////////
579
- $ notificationCenterA ->cleanAllNotifications ();
604
+ $ notificationCenterA ->clearAllNotificationListeners ();
605
+ }
606
+
607
+ public function testcleanAllNotificationsAndVerifyThatclearAllNotificationListenersIsCalled ()
608
+ {
609
+ # Mock NotificationCenter
610
+ $ this ->notificationCenterMock = $ this ->getMockBuilder (NotificationCenter::class)
611
+ ->setConstructorArgs (array ($ this ->loggerMock , $ this ->errorHandlerMock ))
612
+ ->setMethods (array ('clearAllNotificationListeners ' ))
613
+ ->getMock ();
614
+
615
+ # Log deprecation message
616
+ $ this ->loggerMock ->expects ($ this ->at (0 ))
617
+ ->method ('log ' )
618
+ ->with (
619
+ Logger::WARNING ,
620
+ sprintf ("'cleanAllNotifications' is deprecated. Call 'clearAllNotificationListeners' instead. " )
621
+ );
622
+
623
+ $ this ->notificationCenterMock ->expects ($ this ->once ())
624
+ ->method ('clearAllNotificationListeners ' );
625
+
626
+ $ this ->notificationCenterMock ->cleanAllNotifications ();
580
627
}
581
628
582
629
public function testsendNotificationsGivenLessThanExpectedNumberOfArguments ()
583
630
{
584
631
$ clientObj = new FireNotificationTester ;
585
- $ this ->notificationCenterObj ->cleanAllNotifications ();
632
+ $ this ->notificationCenterObj ->clearAllNotificationListeners ();
586
633
587
634
// add a notification callback with arguments
588
635
$ this ->notificationCenterObj ->addNotificationListener (
@@ -610,7 +657,7 @@ public function testsendNotificationsAndVerifyThatAllCallbacksWithoutArgsAreCall
610
657
->setMethods (array ('decision_callback_no_args ' , 'decision_callback_no_args_2 ' , 'track_callback_no_args ' ))
611
658
->getMock ();
612
659
613
- $ this ->notificationCenterObj ->cleanAllNotifications ();
660
+ $ this ->notificationCenterObj ->clearAllNotificationListeners ();
614
661
615
662
//add notification callbacks
616
663
$ this ->notificationCenterObj ->addNotificationListener (
@@ -661,7 +708,7 @@ public function testsendNotificationsAndVerifyThatAllCallbacksWithArgsAreCalled(
661
708
->setMethods (array ('decision_callback_with_args ' , 'decision_callback_with_args_2 ' , 'track_callback_no_args ' ))
662
709
->getMock ();
663
710
664
- $ this ->notificationCenterObj ->cleanAllNotifications ();
711
+ $ this ->notificationCenterObj ->clearAllNotificationListeners ();
665
712
666
713
//add notification callbacks with args
667
714
$ this ->notificationCenterObj ->addNotificationListener (
0 commit comments