/** * @test */ function it_detaches_a_listener() { $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]); $handler = $this->proophActionEventEmitter->attachListener("test", $listener1); $this->proophActionEventEmitter->attachListener("test", $listener2); $this->proophActionEventEmitter->detachListener($handler); $this->proophActionEventEmitter->dispatch($actionEvent); $this->assertNull($listener1->lastEvent); $this->assertSame($actionEvent, $lastEvent); }
/** * @test */ public function it_returns_false_when_unattached_listener_handler_gets_detached() { $listener = $this->getMockForAbstractClass(ListenerHandler::class); $this->assertFalse($this->proophActionEventEmitter->detachListener($listener)); }