コード例 #1
0
 /**
  * @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());
 }
コード例 #2
0
 /**
  * @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];
 }