public function testFormatALotOfResults() { $nbBooks = 50; $con = Propel::getConnection(BookPeer::DATABASE_NAME); Propel::disableInstancePooling(); $book = new Book(); for ($i = 0; $i < $nbBooks; $i++) { $book->clear(); $book->setTitle('BookTest' . $i); $book->save($con); } $stmt = $con->query('SELECT * FROM book'); $formatter = new PropelOnDemandFormatter(); $formatter->init(new ModelCriteria('bookstore', 'Book')); $books = $formatter->format($stmt); $this->assertTrue($books instanceof PropelOnDemandCollection, 'PropelOnDemandFormatter::format() returns a PropelOnDemandCollection'); $this->assertEquals($nbBooks, count($books), 'PropelOnDemandFormatter::format() returns a collection that counts as many rows as the results in the query'); $i = 0; foreach ($books as $book) { $this->assertTrue($book instanceof Book, 'PropelOnDemandFormatter::format() returns a collection of Model objects'); $this->assertEquals('BookTest' . $i, $book->getTitle(), 'PropelOnDemandFormatter::format() returns the model objects matching the query'); $i++; } Propel::enableInstancePooling(); }
public function testClear() { $b = new Book(); $b->setNew(false); $b->clear(); $this->assertTrue($b->isNew(), 'clear() sets the object to new'); $b = new Book(); $b->setDeleted(true); $b->clear(); $this->assertFalse($b->isDeleted(), 'clear() sets the object to not deleted'); }
/** * Test the clearing of related object collection via a many-to-many association. * @link http://www.propelorm.org/ticket/1374 */ public function testClearCrossFk() { $book = new Book(); $bookClub = new BookClubList(); $book->addBookClubList($bookClub); $this->assertEquals(1, count($book->getBookClubLists())); $book->clear(); $this->assertEquals(0, count($book->getBookClubLists())); }