/** * @covers \PhpCqrs\Command\Dispatcher\LocatorCommandDispatcher::__construct * @covers \PhpCqrs\Command\Dispatcher\LocatorCommandDispatcher::dispatch */ public function testCanDispatchCommand() { $locator = new InMemoryLocator(); $handler = new PublishBookCommandHandler(); $locator->register($handler, 'PublishBook'); $dispatcher = new LocatorCommandDispatcher($locator); $payload = new PublishBook('1234'); $message = GenericCommandMessage::forPayload($payload); $dispatcher->dispatch($message); $this->assertSame($payload, $handler->handled()); }
/** * @covers \PhpCqrs\Command\Dispatcher\Middleware\CommandHandler\CommandHandlerMiddleware::__construct * @covers \PhpCqrs\Command\Dispatcher\Middleware\CommandHandler\CommandHandlerMiddleware::handle */ public function testCanHandleCommand() { $payload = new PublishBook('1234'); $handler = new PublishBookCommandHandler(); $message = GenericCommandMessage::forPayload($payload); $locator = new InMemoryLocator(); $locator->register($handler, 'PublishBook'); $middleware = new CommandHandlerMiddleware($locator); $chain = new InMemoryMiddlewareChain(); $this->assertSame($message, $middleware->handle($message, $chain)); $this->assertSame($payload, $handler->handled()); }
/** * @covers \PhpCqrs\Command\Handler\Locator\InMemoryLocator::locate * @expectedException \PhpCqrs\Command\Handler\Locator\Exception\NoCommandHandlerFound */ public function testCanNotLocateCommandHandler() { $message = GenericCommandMessage::forPayload(new PublishBook('1234')); $locator = new InMemoryLocator(); $locator->locate($message); }