function it_returns_exactly_one_result_when_searching_by_exact_isbn_and_it_matches(BookInterface $book) { $isbn = new Isbn('978-1-56619-909-4'); $book->isbn()->willReturn($isbn); $this->add($book); $this->searchByIsbn($isbn)->shouldBe(SearchResults::fromArrayOfBooks(array($book))); }
public function add(BookInterface $book) { $isbn = $book->isbn(); if ($this->hasBookWithIsbn($isbn)) { throw new \InvalidArgumentException(sprintf('Book with ISBN "%s" already exists!', $isbn)); } $this->books[(string) $isbn] = $book; }
function it_throws_an_exception_if_book_with_given_isbn_already_exists(BookInterface $book, ObjectManager $doctrineManager, ObjectRepository $doctrineRepository) { $isbn = new Isbn('978-1-56619-909-4'); $book->isbn()->willReturn($isbn); $doctrineRepository->findOneBy(array('isbn.number' => $isbn))->willReturn($book); $doctrineManager->persist($book)->shouldNotBeCalled(); $doctrineManager->flush()->shouldNotBeCalled(); $this->shouldThrow(new \InvalidArgumentException('Book with ISBN "978-1-56619-909-4" already exists!'))->duringAdd($book); }
public function add(BookInterface $book) { $isbn = $book->isbn(); if ($this->hasBookWithIsbn($isbn)) { throw new \InvalidArgumentException(sprintf('Book with ISBN "%s" already exists!', $isbn)); } $this->doctrineManager->persist($book); $this->doctrineManager->flush(); }