public function testAddAuthorActionSendsAddAuthorCommand() { $this->commandBus->expects(self::once())->method('send')->will(self::returnCallback(function (Command $command) { self::assertInstanceOf(AddAuthor::class, $command); })); $id = Uuid::createNew(); $book = new Book($id, new Authors(), 'title', 'isbn', true, -1); $this->service->expects(self::atLeastOnce())->method('getBook')->will(self::returnValue($book)); $author = new Author('first', 'last'); $resource = AuthorResource::createFromReadModel($author); $controller = new BooksController($this->viewBuilder, $this->service, $this->commandBus); $controller->addAuthorAction($id, $resource, -1); }
/** * @param Uuid $id * @return BookReadModel * @throws NotFoundHttpException */ private function getBook(Uuid $id) { try { return $this->bookService->getBook($id); } catch (ObjectNotFoundException $e) { throw new NotFoundHttpException($e->getMessage(), $e); } }
/** * @Rest\Post("", * condition="request.headers.get('content-type') matches '/domain-model=add-book/i'" * ) * @Rest\View(statusCode=201) * * @ParamConverter("bookResource", * class="AppBundle\Controller\Resource\Book", * converter="fos_rest.request_body" * ) * * @param BookResource $bookResource * @return View * @throws HttpException */ public function addBookAction(BookResource $bookResource) { $id = Uuid::createNew(); $authors = array_map(function (AuthorResource $author) use($id) { return new AddAuthor($id, $author->getFirstName(), $author->getLastName(), -1); }, $bookResource->getAuthors()); $command = new AddBook($id, $authors, $bookResource->getTitle(), $bookResource->getISBN()); $this->commandBus->send($command); $book = $this->bookService->getBook($id); return $this->viewBuilder->setDocument($book)->setVersion()->setLocation(static::BASE_ROUTE . $book->getId())->build(); }
public function testApplyConverterOnVersionWithInvalidVersionThrowsException() { self::setExpectedException(PreconditionFailedHttpException::class); $id = Uuid::createNew(); $version = 1; $book = new BookReadModel($id, new Authors(), 'title', 'isbn', true, $version); $request = Request::createFromGlobals(); $request->headers->set('if-none-match', 'foo'); $request->attributes->set('id', $id); $this->bookService->expects(self::once())->method('getBook')->with($id)->will(self::returnValue($book)); $this->configuration->expects(self::atLeastOnce())->method('getName')->will(self::returnValue('version')); $this->configuration->expects(self::once())->method('getOptions')->will(self::returnValue(['id' => 'id'])); $this->configuration->expects(self::once())->method('getClass')->will(self::returnValue(BookReadModel::class)); $converter = new ParamConverter($this->bookService, $this->userService); $converter->apply($request, $this->configuration); }
public function testGetAllRetrievesAll() { $storage = $this->getMockBuilder(Storage::class)->disableOriginalConstructor()->getMock(); $storage->expects(self::once())->method('findAll'); $service = new BookService($storage); $service->getAll(); }