@@ -182,6 +182,7 @@ public function testTriggerUntilShouldMarkResponseCollectionStoppedWhenCondition
182182 $ this ->events ->attach ('foo.bar ' , function () { return 'found ' ; }, 2 );
183183 $ this ->events ->attach ('foo.bar ' , function () { return 'zero ' ; }, 1 );
184184 // @codingStandardsIgnoreEnd
185+
185186 $ responses = $ this ->events ->triggerUntil (function ($ result ) {
186187 return ($ result === 'found ' );
187188 }, 'foo.bar ' , $ this );
@@ -200,6 +201,7 @@ public function testTriggerUntilShouldMarkResponseCollectionStoppedWhenCondition
200201 $ this ->events ->attach ('foo.bar ' , function () { return 'zero ' ; });
201202 $ this ->events ->attach ('foo.bar ' , function () { return 'found ' ; });
202203 // @codingStandardsIgnoreEnd
204+
203205 $ responses = $ this ->events ->triggerUntil (function ($ result ) {
204206 return ($ result === 'found ' );
205207 }, 'foo.bar ' , $ this );
@@ -216,6 +218,7 @@ public function testResponseCollectionIsNotStoppedWhenNoCallbackMatchedByTrigger
216218 $ this ->events ->attach ('foo.bar ' , function () { return 'found ' ; }, 2 );
217219 $ this ->events ->attach ('foo.bar ' , function () { return 'zero ' ; }, 1 );
218220 // @codingStandardsIgnoreEnd
221+
219222 $ responses = $ this ->events ->triggerUntil (function ($ result ) {
220223 return ($ result === 'never found ' );
221224 }, 'foo.bar ' , $ this );
@@ -232,6 +235,7 @@ public function testCallingEventsStopPropagationMethodHaltsEventEmission()
232235 $ this ->events ->attach ('foo.bar ' , function ($ e ) { return 'found ' ; }, 2 );
233236 $ this ->events ->attach ('foo.bar ' , function ($ e ) { return 'zero ' ; }, 1 );
234237 // @codingStandardsIgnoreEnd
238+
235239 $ responses = $ this ->events ->trigger ('foo.bar ' );
236240 $ this ->assertInstanceOf ('Zend\EventManager\ResponseCollection ' , $ responses );
237241 $ this ->assertTrue ($ responses ->stopped ());
@@ -252,6 +256,7 @@ public function testCanAlterParametersWithinAEvent()
252256 $ bar = $ e ->getParam ('bar ' , '__NO_BAR__ ' );
253257 return $ foo . ": " . $ bar ;
254258 });
259+
255260 $ responses = $ this ->events ->trigger ('foo.bar ' );
256261 $ this ->assertEquals ('bar:baz ' , $ responses ->last ());
257262 }
@@ -260,10 +265,12 @@ public function testParametersArePassedToEventByReference()
260265 {
261266 $ params = [ 'foo ' => 'bar ' , 'bar ' => 'baz ' ];
262267 $ args = $ this ->events ->prepareArgs ($ params );
268+
263269 // @codingStandardsIgnoreStart
264270 $ this ->events ->attach ('foo.bar ' , function ($ e ) { $ e ->setParam ('foo ' , 'FOO ' ); });
265271 $ this ->events ->attach ('foo.bar ' , function ($ e ) { $ e ->setParam ('bar ' , 'BAR ' ); });
266272 // @codingStandardsIgnoreEnd
273+
267274 $ responses = $ this ->events ->trigger ('foo.bar ' , $ this , $ args );
268275 $ this ->assertEquals ('FOO ' , $ args ['foo ' ]);
269276 $ this ->assertEquals ('BAR ' , $ args ['bar ' ]);
@@ -276,6 +283,7 @@ public function testCanPassObjectForEventParameters()
276283 $ this ->events ->attach ('foo.bar ' , function ($ e ) { $ e ->setParam ('foo ' , 'FOO ' ); });
277284 $ this ->events ->attach ('foo.bar ' , function ($ e ) { $ e ->setParam ('bar ' , 'BAR ' ); });
278285 // @codingStandardsIgnoreEnd
286+
279287 $ responses = $ this ->events ->trigger ('foo.bar ' , $ this , $ params );
280288 $ this ->assertEquals ('FOO ' , $ params ->foo );
281289 $ this ->assertEquals ('BAR ' , $ params ->bar );
@@ -744,4 +752,54 @@ public function testTriggeringAnEventWithAnEmptyNameRaisesAnException($event, $m
744752 $ this ->events ->$ method ($ event );
745753 }
746754 }
755+
756+ public function testTriggerEventAcceptsEventInstanceAndTriggersListeners ()
757+ {
758+ $ event = $ this ->prophesize (EventInterface::class);
759+ $ event ->getName ()->willReturn ('test ' );
760+ $ event ->stopPropagation (false )->shouldBeCalled ();
761+ $ event ->propagationIsStopped ()->willReturn (false );
762+
763+ $ triggered = false ;
764+ $ this ->events ->attach ('test ' , function ($ e ) use ($ event , &$ triggered ) {
765+ $ this ->assertSame ($ event ->reveal (), $ e );
766+ $ triggered = true ;
767+ });
768+
769+ $ this ->events ->triggerEvent ($ event ->reveal ());
770+ $ this ->assertTrue ($ triggered , 'Listener for event was not triggered ' );
771+ }
772+
773+ public function testTriggerEventUntilAcceptsEventInstanceAndTriggersListenersUntilCallbackEvaluatesTrue ()
774+ {
775+ $ event = $ this ->prophesize (EventInterface::class);
776+ $ event ->getName ()->willReturn ('test ' );
777+ $ event ->stopPropagation (false )->shouldBeCalled ();
778+ $ event ->propagationIsStopped ()->willReturn (false );
779+
780+ $ callback = function ($ result ) {
781+ return ($ result === true );
782+ };
783+
784+ $ triggeredOne = false ;
785+ $ this ->events ->attach ('test ' , function ($ e ) use ($ event , &$ triggeredOne ) {
786+ $ this ->assertSame ($ event ->reveal (), $ e );
787+ $ triggeredOne = true ;
788+ });
789+
790+ $ triggeredTwo = false ;
791+ $ this ->events ->attach ('test ' , function ($ e ) use ($ event , &$ triggeredTwo ) {
792+ $ this ->assertSame ($ event ->reveal (), $ e );
793+ $ triggeredTwo = true ;
794+ return true ;
795+ });
796+
797+ $ this ->events ->attach ('test ' , function ($ e ) {
798+ $ this ->fail ('Third listener was triggered and should not have been ' );
799+ });
800+
801+ $ this ->events ->triggerEventUntil ($ callback , $ event ->reveal ());
802+ $ this ->assertTrue ($ triggeredOne , 'First Listener for event was not triggered ' );
803+ $ this ->assertTrue ($ triggeredTwo , 'First Listener for event was not triggered ' );
804+ }
747805}
0 commit comments