public function testCreateNewAuthor()
 {
     $mapper = new AuthorMapper($this->connection->getConnection());
     $data = ['name' => 'Rob Allen', 'biography' => 'Lorem ipsum'];
     $author = new Author($data);
     $this->assertEmpty($author->getId());
     $result = $mapper->save($author);
     $this->assertTrue($result);
     $this->assertNotEmpty($author->getId());
     // read database to check we now have three records
     $authors = $mapper->fetchAll();
     $this->assertSame(3, count($authors));
     // Rob Allen will be at index 1 as he's after Anne and before Suzanne
     $this->assertSame('Rob Allen', $authors[1]->getName());
     $this->assertSame('Lorem ipsum', $authors[1]->getBiography());
 }
 public function testThatAnEmptyIdOrBiographyBecomesNull()
 {
     $author = new Author(['id' => '', 'name' => 'Rob', 'biography' => '']);
     $this->assertNull($author->getId());
     $this->assertNull($author->getBiography());
 }
 /**
  * Update a record in the database
  *
  * @param  Author $author
  * @return boolean
  */
 protected function update(Author $author)
 {
     $sql = 'UPDATE author SET name =:name, biography = :biography WHERE id = :id';
     $params = ['name' => $author->getName(), 'biography' => $author->getBiography(), 'id' => $author->getId()];
     $statement = $this->dbAdapter->prepare($sql);
     return $statement->execute($params);
 }