コード例 #1
0
 /**
  * @test
  */
 public function it_returns_nothing_on_dispatch_until_when_no_listeners_attached()
 {
     $actionEventMock = $this->getMock(ActionEvent::class);
     $this->assertNull($this->proophActionEventEmitter->dispatchUntil($actionEventMock, function () {
         return true;
     }));
 }
コード例 #2
0
 /**
  * @test
  */
 function it_triggers_listeners_until_callback_returns_true()
 {
     $lastEvent = null;
     $listener1 = new ActionEventListenerMock();
     $listener2 = function (ActionEvent $event) use(&$lastEvent) {
         if ($event->getParam('payload', false)) {
             $lastEvent = $event;
         }
     };
     $actionEvent = $this->proophActionEventEmitter->getNewActionEvent("test", $this, ['payload' => true]);
     $this->proophActionEventEmitter->attachListener("test", $listener1);
     $this->proophActionEventEmitter->attachListener("test", $listener2);
     $this->proophActionEventEmitter->dispatchUntil($actionEvent, function (ActionEvent $e) {
         //We return true directly after first listener was triggered
         return true;
     });
     $this->assertNull($lastEvent);
     $this->assertSame($actionEvent, $listener1->lastEvent);
 }