/** * This is run after each unit test. It empties the database. */ protected function tearDown() { BookstoreDataPopulator::depopulate(); $this->assertEquals(0, count(BookPeer::doSelect(new Criteria())), "Expect book table to be empty."); $this->assertEquals(0, count(AuthorPeer::doSelect(new Criteria())), "Expect author table to be empty."); $this->assertEquals(0, count(PublisherPeer::doSelect(new Criteria())), "Expect publisher table to be empty."); $this->assertEquals(0, count(ReviewPeer::doSelect(new Criteria())), "Expect review table to be empty."); $this->assertEquals(0, count(MediaPeer::doSelect(new Criteria())), "Expect media table to be empty."); $this->assertEquals(0, count(BookstoreEmployeePeer::doSelect(new Criteria())), "Expect bookstore_employee table to be empty."); $this->assertEquals(0, count(BookstoreEmployeeAccountPeer::doSelect(new Criteria())), "Expect bookstore_employee_account table to be empty."); $this->assertEquals(0, count(BookstoreSalePeer::doSelect(new Criteria())), "Expect bookstore_sale table to be empty."); BookPeer::clearInstancePool(); $this->assertEquals(0, count(BookPeer::$instances), "Expected 0 Book instances after clearInstancePool()"); AuthorPeer::clearInstancePool(); $this->assertEquals(0, count(AuthorPeer::$instances), "Expected 0 Author instances after clearInstancePool()"); PublisherPeer::clearInstancePool(); $this->assertEquals(0, count(PublisherPeer::$instances), "Expected 0 Publisher instances after clearInstancePool()"); ReviewPeer::clearInstancePool(); $this->assertEquals(0, count(ReviewPeer::$instances), "Expected 0 Review instances after clearInstancePool()"); MediaPeer::clearInstancePool(); $this->assertEquals(0, count(MediaPeer::$instances), "Expected 0 Media instances after clearInstancePool()"); BookstoreEmployeePeer::clearInstancePool(); $this->assertEquals(0, count(BookstoreEmployeePeer::$instances), "Expected 0 BookstoreEmployee instances after clearInstancePool()"); BookstoreEmployeeAccountPeer::clearInstancePool(); $this->assertEquals(0, count(BookstoreEmployeeAccountPeer::$instances), "Expected 0 BookstoreEmployeeAccount instances after clearInstancePool()"); BookstoreSalePeer::clearInstancePool(); $this->assertEquals(0, count(BookstoreSalePeer::$instances), "Expected 0 BookstoreSale instances after clearInstancePool()"); parent::tearDown(); }
/** * Test isModified() to be false after setting default value second time */ public function testDefaultValueSetTwice() { $pub = new Publisher(); $pub->setName('Penguin'); $pub->save(); $pubId = $pub->getId(); PublisherPeer::clearInstancePool(); $pub2 = PublisherPeer::retrieveByPK($pubId); $pub2->setName('Penguin'); $this->assertFalse($pub2->isModified(), "Expect Publisher to be not modified after setting default value second time."); }
public function testRefFKGetJoin() { BookstoreDataPopulator::populate(); BookPeer::clearInstancePool(); AuthorPeer::clearInstancePool(); PublisherPeer::clearInstancePool(); $con = Propel::getConnection(BookPeer::DATABASE_NAME); $author = AuthorPeer::doSelectOne(new Criteria(), $con); // populate book instance pool $books = $author->getBooksJoinPublisher(null, $con); $sql = $con->getLastExecutedQuery(); $publisher = $books[0]->getPublisher($con); $this->assertEquals($sql, $con->getLastExecutedQuery(), 'refFK getter uses instance pool if possible'); }
public function testToArrayIncludeForeignObjects() { BookstoreDataPopulator::populate(); BookPeer::clearInstancePool(); AuthorPeer::clearInstancePool(); PublisherPeer::clearInstancePool(); $c = new Criteria(); $c->add(BookPeer::TITLE, 'Don Juan'); $books = BookPeer::doSelectJoinAuthor($c); $book = $books[0]; $arr1 = $book->toArray(BasePeer::TYPE_PHPNAME, null, true); $expectedKeys = array('Id', 'Title', 'ISBN', 'Price', 'PublisherId', 'AuthorId', 'Author'); $this->assertEquals($expectedKeys, array_keys($arr1), 'toArray() can return sub arrays for hydrated related objects'); $this->assertEquals('George', $arr1['Author']['FirstName'], 'toArray() can return sub arrays for hydrated related objects'); $c = new Criteria(); $c->add(BookPeer::TITLE, 'Don Juan'); $books = BookPeer::doSelectJoinAll($c); $book = $books[0]; $arr2 = $book->toArray(BasePeer::TYPE_PHPNAME, null, true); $expectedKeys = array('Id', 'Title', 'ISBN', 'Price', 'PublisherId', 'AuthorId', 'Publisher', 'Author'); $this->assertEquals($expectedKeys, array_keys($arr2), 'toArray() can return sub arrays for hydrated related objects'); }