/** * @covers \PhpCqrs\Command\Handler\Locator\Exception\NoCommandHandlerFound::forMessage */ public function testCanConstructFromCommand() { $message = GenericCommandMessage::forPayload(new RegisterBook('1234', 'Title!')); $exception = NoCommandHandlerFound::forMessage($message); $this->assertInstanceOf(NoCommandHandlerFound::class, $exception); $this->assertSame('No command handler found for command RegisterBook.', $exception->getMessage()); }
/** * @param CommandMessage $message * @return CommandHandler * @throws NoCommandHandlerFound */ public function locate(CommandMessage $message) { $name = $message->name(); if (!array_key_exists($name, $this->registry)) { throw NoCommandHandlerFound::forMessage($message); } return $this->registry[$name]; }