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();
 }
Пример #2
0
 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');
 }
Пример #3
0
 /**
  * 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()));
 }
Пример #4
0
 public function testFormatALotOfResults()
 {
     $nbBooks = 50;
     $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
     Propel::disableInstancePooling();
     $book = new Book();
     for ($i = 0; $i < $nbBooks; $i++) {
         $book->clear();
         $book->setTitle('BookTest' . $i);
         $book->setISBN('FA404-' . $i);
         $book->save($con);
     }
     $stmt = $con->query('SELECT id, title, isbn, price, publisher_id, author_id FROM book ORDER BY book.ID ASC');
     $formatter = new OnDemandFormatter();
     $formatter->init(new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book'));
     $books = $formatter->format($stmt);
     $this->assertTrue($books instanceof OnDemandCollection, 'OnDemandFormatter::format() returns a PropelOnDemandCollection');
     $this->assertEquals($nbBooks, count($books), 'OnDemandFormatter::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, 'OnDemandFormatter::format() returns a collection of Model objects');
         $this->assertEquals('BookTest' . $i, $book->getTitle(), 'OnDemandFormatter::format() returns the model objects matching the query');
         $i++;
     }
     Propel::enableInstancePooling();
 }