public function testToArray() { $book = new Book(); $title = 'test title'; $author = 'test author'; $book->setTitle($title); $book->setAuthor($author); $result = $book->toArray(); $this->assertTrue(is_array($result)); $this->assertTrue(array_key_exists('id', $result)); $this->assertTrue(isset($result['title'])); $this->assertTrue(isset($result['author'])); $this->assertEquals($title, $result['title']); $this->assertEquals($author, $result['author']); }
/** * Only the create function should work. Other methods should trigger * exceptions indicating those RUD methods are not supported by this * strategy. * * @param array $write_strategies * @param array $read_strategies */ protected function _testGoldenCPath(array $write_strategies, array $read_strategies) { // Create a DAO. $bookDao = new BookDao($write_strategies, $read_strategies); // Make a book and set its properties. $book = new Book(); $title = uniqid(); $author = uniqid(); $book->setTitle($title); $book->setAuthor($author); // Run the "C" create function. $bookDao->create($book); // Ensure a UUID was defined as the id. $this->assertTrue(strlen($book->getId()) == 36); $correctReadExceptionDetected = false; $correctUpdateExceptionDetected = false; $correctDeleteExceptionDetected = false; // Do a "R"ead and ensure everything comes back. try { $returnedBook = $bookDao->read($book->getId()); } catch (\Octopus\Strategy\Exception\InvalidStrategyMethod $e) { $correctReadExceptionDetected = true; } // "U"pdate the record. try { $book->setTitle('foo123'); $bookDao->update($book); } catch (\Octopus\Strategy\Exception\InvalidStrategyMethod $e) { $correctUpdateExceptionDetected = true; } // "R"emove it try { $bookDao->delete($book); } catch (\Octopus\Strategy\Exception\InvalidStrategyMethod $ex) { $correctDeleteExceptionDetected = true; } $this->assertTrue($correctReadExceptionDetected); $this->assertTrue($correctUpdateExceptionDetected); $this->assertTrue($correctDeleteExceptionDetected); }