From 5700f85cf7ab3d15ba651775f9e33c1936a72656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vi=CC=81ctor=20Falco=CC=81n?= Date: Thu, 2 Jul 2026 15:18:52 +0200 Subject: [PATCH] test(events): guard against double-registered transaction listeners The PHP-LARAVEL-3V fix removed the explicit Event::listen calls that, combined with event discovery, registered each transaction listener twice. Add a regression test that fires each transaction event and asserts its queued listener is dispatched exactly once, so re-adding an explicit registration (or otherwise double-wiring) fails CI. --- .../TransactionListenerRegistrationTest.php | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/Feature/Events/TransactionListenerRegistrationTest.php diff --git a/tests/Feature/Events/TransactionListenerRegistrationTest.php b/tests/Feature/Events/TransactionListenerRegistrationTest.php new file mode 100644 index 00000000..c5e47067 --- /dev/null +++ b/tests/Feature/Events/TransactionListenerRegistrationTest.php @@ -0,0 +1,33 @@ +filter(fn (CallQueuedListener $job): bool => $job->class === $listener) + ->count(); +} + +it('registers each transaction listener exactly once', function (string $event, string $listener): void { + $user = User::factory()->onboarded()->create(); + $transaction = Transaction::factory()->plaintext()->create(['user_id' => $user->id]); + + Queue::fake(); + + event(new $event($transaction)); + + expect(queuedListenerCount($listener))->toBe(1); +})->with([ + 'created dispatches budget assignment once' => [TransactionCreated::class, AssignTransactionToBudget::class], + 'updated dispatches budget assignment once' => [TransactionUpdated::class, AssignTransactionToBudget::class], + 'deleted dispatches budget unassignment once' => [TransactionDeleted::class, UnassignTransactionFromBudget::class], +]);