Commit 9c3eb6e25d0 for woocommerce
commit 9c3eb6e25d0497e565323c7a760036dae8b19dc3
Author: Peter Petrov <peter.petrov89@gmail.com>
Date: Fri Apr 17 09:27:20 2026 +0300
Add tests to verify PendingNotificationStore dispatches notifications (#64185)
* Add tests to verify PendingNotificationStore dispatches notifications
The existing test_dispatch_all_clears_store only asserted the store was
empty after dispatch, which would pass even if the dispatcher call were
removed. Two new tests verify the dispatcher is actually invoked (or not)
depending on whether notifications are pending.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Clean up shutdown hook in test_dispatch_all_calls_dispatcher
The local $store registers a shutdown callback via add() but tearDown()
only removes the hook for $this->store, leaking a global hook.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
diff --git a/plugins/woocommerce/tests/php/src/Internal/PushNotifications/Services/PendingNotificationStoreTest.php b/plugins/woocommerce/tests/php/src/Internal/PushNotifications/Services/PendingNotificationStoreTest.php
index a337009855d..26a7b522d19 100644
--- a/plugins/woocommerce/tests/php/src/Internal/PushNotifications/Services/PendingNotificationStoreTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/PushNotifications/Services/PendingNotificationStoreTest.php
@@ -131,6 +131,39 @@ class PendingNotificationStoreTest extends WC_Unit_Test_Case {
$this->assertSame( 0, $this->store->count() );
}
+ /**
+ * @testdox Should call the dispatcher when dispatching pending notifications.
+ */
+ public function test_dispatch_all_calls_dispatcher(): void {
+ $dispatcher = $this->createMock( InternalNotificationDispatcher::class );
+ $dispatcher->expects( $this->once() )
+ ->method( 'dispatch' );
+
+ $store = new PendingNotificationStore();
+ $store->init( $dispatcher );
+ $store->register();
+ $store->add( $this->create_order_mock( 1 ) );
+
+ $store->dispatch_all();
+
+ remove_action( 'shutdown', array( $store, 'dispatch_all' ) );
+ }
+
+ /**
+ * @testdox Should not call the dispatcher when there are no pending notifications.
+ */
+ public function test_dispatch_all_does_not_call_dispatcher_when_empty(): void {
+ $dispatcher = $this->createMock( InternalNotificationDispatcher::class );
+ $dispatcher->expects( $this->never() )
+ ->method( 'dispatch' );
+
+ $store = new PendingNotificationStore();
+ $store->init( $dispatcher );
+ $store->register();
+
+ $store->dispatch_all();
+ }
+
/**
* @testdox Should return all pending notifications via get_all.
*/