/** * @param ReadModel $book * @return Book */ public static function createFromReadModel(ReadModel $book) { $authors = array_map(function (AuthorReadModel $author) { return Author::createFromReadModel($author); }, iterator_to_array($book->getAuthors()->getIterator())); return new self($book->getId()->getValue(), $authors, $book->getTitle(), $book->getISBN(), $book->isAvailable()); }
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); }