コード例 #1
0
 public function testThatEmptyFieldsBecomeNull()
 {
     $book = new Book(['id' => '', 'author_id' => '1234', 'title' => 'Lorem ipsum', 'isdn' => '', 'date_published' => '']);
     $this->assertNull($book->getId());
     $this->assertNull($book->getIsbn());
     $this->assertNull($book->getDatePublished());
 }
コード例 #2
0
 public function testCreateNewBook()
 {
     $mapper = new BookMapper($this->connection->getConnection());
     $data = ['author_id' => 'f075512f-9734-304c-b839-b86174143c07', 'title' => 'Lorem ipsum', 'isbn' => '9780689305078', 'date_published' => '2099-01-01'];
     $book = new Book($data);
     $this->assertEmpty($book->getId());
     $result = $mapper->save($book);
     $this->assertTrue($result);
     $this->assertNotEmpty($book->getId());
     // read database to check we now have three records
     $books = $mapper->fetchAll();
     $this->assertSame(4, count($books));
     // This book will be last as it's title starts with zzz
     $this->assertSame($data['author_id'], $books[3]->getAuthorid());
     $this->assertSame($data['title'], $books[3]->getTitle());
 }
コード例 #3
0
 /**
  * Update a record in the database
  *
  * @param  Book $book
  * @return boolean
  */
 protected function update(Book $book)
 {
     $sql = 'UPDATE book SET author_id =:author_id, title = :title,
             isbn = :isbn, date_published = :date_published
             WHERE id = :id';
     $params = ['author_id' => $book->getAuthorId(), 'title' => $book->getTitle(), 'isbn' => $book->getIsbn(), 'date_published' => $book->getDatePublished(), 'id' => $book->getId()];
     $statement = $this->dbAdapter->prepare($sql);
     return $statement->execute($params);
 }