@@ -126,15 +126,32 @@ public function test_closure_based_handlers_using_listen_method(): void
126126 $ hasHappened = false ;
127127
128128 // @mago-expect best-practices/no-unused-parameter
129- $ eventBus ->listen (' my-event ' , function (string $ event ) use (&$ hasHappened ): void {
129+ $ eventBus ->listen (function (string $ event ) use (&$ hasHappened ): void {
130130 $ hasHappened = true ;
131- });
131+ }, event: ' my-event ' );
132132
133133 $ eventBus ->dispatch ('my-event ' );
134134
135135 $ this ->assertTrue ($ hasHappened );
136136 }
137137
138+ public function test_closure_based_handlers_using_listen_method_and_first_parameter (): void
139+ {
140+ $ container = new GenericContainer ();
141+ $ config = new EventBusConfig ();
142+ $ eventBus = new GenericEventBus ($ container , $ config );
143+ $ hasHappened = false ;
144+
145+ // @mago-expect best-practices/no-unused-parameter
146+ $ eventBus ->listen (function (ItHappened $ event ) use (&$ hasHappened ): void {
147+ $ hasHappened = true ;
148+ });
149+
150+ $ eventBus ->dispatch (new ItHappened ());
151+
152+ $ this ->assertTrue ($ hasHappened );
153+ }
154+
138155 public function test_closure_based_handlers_using_function (): void
139156 {
140157 GenericContainer::setInstance ($ container = new GenericContainer ());
@@ -145,9 +162,9 @@ public function test_closure_based_handlers_using_function(): void
145162 $ hasHappened = false ;
146163
147164 // @mago-expect best-practices/no-unused-parameter
148- listen (' my-event ' , function (string $ event ) use (&$ hasHappened ): void {
165+ listen (function (string $ event ) use (&$ hasHappened ): void {
149166 $ hasHappened = true ;
150- });
167+ }, event: ' my-event ' );
151168
152169 get (EventBus::class)->dispatch ('my-event ' );
153170
0 commit comments