public function testCommandBusHandleCommandThrowsExceptionIfNoHandlerExist() { self::setExpectedException(NoCommandHandlerException::class); $command = $this->getMockBuilder(Command::class)->disableOriginalConstructor()->getMock(); $commandBus = new CommandBus([]); $commandBus->send($command); }
/** * @Rest\Put("", * condition="request.headers.get('content-type') matches '/domain-model=create-user/i'" * ) * @Rest\View() * * @ParamConverter("userResource", * class="AppBundle\Controller\Resource\User", * converter="fos_rest.request_body" * ) * * @param UserResource $userResource * @return View * @throws HttpException */ public function createAction(UserResource $userResource) { $user = $this->userService->getUserByUserName($userResource->getUserName()); if ($user != null) { return $this->viewBuilder->setStatus(204)->setVersion($user)->setLocation(static::BASE_ROUTE . $user->getId())->build(); } $id = Uuid::createNew(); $command = new CreateUser($id, $userResource->getUserName(), $userResource->getEmailAddress(), $userResource->getFullName()); $this->commandBus->send($command); $user = $this->userService->getUser($id); return $this->viewBuilder->setDocument($user)->setVersion()->setLocation(static::BASE_ROUTE . $user->getId())->setStatus(201)->build(); }
/** * @Rest\Put("/{id}", * condition="request.headers.get('content-type') matches '/domain-model=return/i'", * requirements={ * "id"="[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}" * }, * defaults={ * "id"=null * } * ) * @Rest\View(statusCode=204) * * @ParamConverter("id", * class="AppBundle\EventSourcing\EventStore\Uuid", * converter="param_converter" * ) * @ParamConverter("version", * class="AppBundle\Domain\ReadModel\Book", * options={ * "id": "id" * }, * converter="param_converter" * ) * * @param Uuid $id * @param integer $version */ public function returnBookAction(Uuid $id, $version) { $command = new ReturnBook($id, $version); $this->commandBus->send($command); }