public function testAddBookActionSendsAddBookCommand()
 {
     $this->commandBus->expects(self::once())->method('send')->will(self::returnCallback(function (Command $command) {
         self::assertInstanceOf(AddBook::class, $command);
     }));
     $book = new Book(Uuid::createFromValue(null), new Authors([new Author('first', 'last')]), 'title', 'isbn', true, -1);
     $resource = BookResource::createFromReadModel($book);
     $this->service->expects(self::once())->method('getBook')->will(self::returnValue($book));
     $controller = new BooksController($this->viewBuilder, $this->service, $this->commandBus);
     $controller->addBookAction($resource);
 }
 public function testExecuteRetrievesIdentitiesFromEventStoreAndInsertsDocumentsIntoReadStore()
 {
     $eventStore = $this->getMockBuilder(EventStore::class)->disableOriginalConstructor()->getMock();
     $readStore = $this->getMockBuilder(Storage::class)->disableOriginalConstructor()->getMock();
     $identities = [Uuid::createFromValue(1), Uuid::createFromValue(2), Uuid::createFromValue(3), Uuid::createFromValue(4), Uuid::createFromValue(5)];
     $eventStore->expects(self::once())->method('getAggregateIds')->will(self::returnValue($identities));
     $eventStore->expects(self::exactly(count($identities)))->method('getEventsForAggregate')->will(self::returnCallback(function (Uuid $id) {
         return new Events([new BookAdded($id, [new AuthorAdded($id, 'first', 'last')], 'title', 'isbn'), new AuthorAdded($id, 'first', 'last'), new BookCheckedOut($id, Uuid::createNew())]);
     }));
     $readStore->expects(self::exactly(count($identities)))->method('upsert');
     $in = $this->getMockBuilder(InputInterface::class)->getMockForAbstractClass();
     $out = $this->getMockBuilder(OutputInterface::class)->getMockForAbstractClass();
     $reload = new ReloadBookReadStore($eventStore, $readStore);
     $reload->run($in, $out);
 }
Esempio n. 3
0
 /**
  * @param Request $request
  * @param ParamConfiguration $configuration
  * @return Uuid
  * @throws BadRequestHttpException
  */
 protected function convertUuid(Request $request, ParamConfiguration $configuration)
 {
     $uuid = $request->attributes->get($configuration->getName());
     if (empty($uuid)) {
         throw new BadRequestHttpException("Uuid value of '{$configuration->getName()}' must not be empty.");
     }
     return Uuid::createFromValue($uuid);
 }
Esempio n. 4
0
 /**
  * @Rest\Put("/{id}",
  *  condition="request.headers.get('content-type') matches '/domain-model=checkout/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"
  * )
  * @Rest\QueryParam(
  *  name="user_id",
  *  key=null,
  *  requirements="[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}",
  *  default=null,
  *  description="The user ID of the user that checks out the book.",
  *  strict=true,
  *  array=false,
  *  nullable=false
  * )
  *
  * @param Uuid $id
  * @param integer $version
  * @param ParamFetcherInterface $params
  * @throws HttpException
  */
 public function checkOutBookAction(Uuid $id, $version, ParamFetcherInterface $params)
 {
     $userId = Uuid::createFromValue($params->get('user_id'));
     $command = new CheckOutBook($id, $userId, $version);
     try {
         $this->commandBus->send($command);
     } catch (BookUnavailableException $e) {
         throw new PreconditionFailedHttpException($e->getMessage(), $e);
     }
 }
Esempio n. 5
0
 /**
  * @return Uuid[]
  */
 public function getAggregateIds()
 {
     return array_map(function ($identity) {
         return Uuid::createFromValue($identity);
     }, $this->storage->findIdentities());
 }
 public function getId()
 {
     return Uuid::createFromValue(1);
 }