/** * Updates an existing book * * @param $id * @param $data * @return Book * @throws BookNotFoundException */ public function update($id, $data) { $name = $this->nameIsRequired($data); $isbn = $this->isbnIsRequired($data); $book = $this->bookRepo->bookOfId($id); if (!$book) { throw new BookNotFoundException($id); } $book->setName($name); $book->setIsbn($isbn); $this->setDescription($data, $book); $this->setAgeRange($data, $book); $this->addImage($data, $book); $this->syncAuthors($data, $book); $this->syncPublishers($data, $book); $this->syncTags($data, $book); $this->bookRepo->update($book); return $book; }
/** * @test * @group bookrepo */ public function should_return_null_when_book_of_id_not_found() { $id = 9999999999; $book = $this->bookRepo->bookOfId($id); $this->assertNull($book); }