/** * @test */ public function itOnlyCallsTheListenerSubscribedToAGivenEvent() { $this->dispatcher->addListener('event1', [$this->listener1, 'handleEvent']); $this->dispatcher->addListener('event2', [$this->listener2, 'handleEvent']); $this->dispatcher->dispatch('event1', 'value1', 'value2'); $this->assertTrue($this->listener1->isCalled()); $this->assertFalse($this->listener2->isCalled()); }
/** * {@inheritDoc} */ public function execute($command) { try { $this->commandBus->execute($command); $this->dispatcher->dispatch(self::EVENT_COMMAND_SUCCESS, ['command' => $command]); } catch (\Exception $e) { $this->dispatcher->dispatch(self::EVENT_COMMAND_FAILURE, ['command' => $command, 'exception' => $e]); throw $e; } }