本文整理汇总了PHP中Propel\Tests\Helpers\Bookstore\BookstoreDataPopulator::populate方法的典型用法代码示例。如果您正苦于以下问题:PHP BookstoreDataPopulator::populate方法的具体用法?PHP BookstoreDataPopulator::populate怎么用?PHP BookstoreDataPopulator::populate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Propel\Tests\Helpers\Bookstore\BookstoreDataPopulator
的用法示例。
在下文中一共展示了BookstoreDataPopulator::populate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testRefFKGetJoin
public function testRefFKGetJoin()
{
BookstoreDataPopulator::populate();
BookPeer::clearInstancePool();
AuthorPeer::clearInstancePool();
PublisherPeer::clearInstancePool();
$con = Propel::getServiceContainer()->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');
}
示例2: setUp
protected function setUp()
{
parent::setUp();
BookstoreDataPopulator::populate($this->con);
Propel::disableInstancePooling();
$this->books = PropelQuery::from('\\Propel\\Tests\\Bookstore\\Book')->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)->find();
}
示例3: testQuery
public function testQuery()
{
BookstoreDataPopulator::depopulate();
BookstoreDataPopulator::populate();
$book = PropelQuery::from('\\Propel\\Tests\\Bookstore\\Book b')->where('b.Title like ?', 'Don%')->orderBy('b.ISBN', 'desc')->findOne();
$this->assertTrue($book instanceof Book);
$this->assertEquals('Don Juan', $book->getTitle());
}
示例4: setUp
protected function setUp()
{
parent::setUp();
BookstoreDataPopulator::populate();
$this->sampleLobFiles['tin_drum.gif'] = TESTS_BASE_DIR . '/Fixtures/etc/lob/tin_drum.gif';
$this->sampleLobFiles['tin_drum.txt'] = TESTS_BASE_DIR . '/Fixtures/etc/lob/tin_drum.txt';
$this->sampleLobFiles['propel.gif'] = TESTS_BASE_DIR . '/Fixtures/etc/lob/propel.gif';
}
示例5: setUp
protected function setUp()
{
parent::setUp();
BookstoreDataPopulator::populate();
$cr = new Criteria();
$cr->add(AuthorPeer::LAST_NAME, "Rowling");
$cr->add(AuthorPeer::FIRST_NAME, "J.K.");
$rowling = AuthorPeer::doSelectOne($cr);
$this->authorId = $rowling->getId();
$book = new Book();
$book->setTitle("Harry Potter and the Philosopher's Stone");
$book->setISBN("1234");
$book->setAuthor($rowling);
$book->save();
$this->books[] = $book->getId();
$book = new Book();
$book->setTitle("Harry Potter and the Chamber of Secrets");
$book->setISBN("1234");
$book->setAuthor($rowling);
$book->save();
$this->books[] = $book->getId();
$book = new Book();
$book->setTitle("Harry Potter and the Prisoner of Azkaban");
$book->setISBN("1234");
$book->setAuthor($rowling);
$book->save();
$this->books[] = $book->getId();
$book = new Book();
$book->setTitle("Harry Potter and the Goblet of Fire");
$book->setISBN("1234");
$book->setAuthor($rowling);
$book->save();
$this->books[] = $book->getId();
$book = new Book();
$book->setTitle("Harry Potter and the Half-Blood Prince");
$book->setISBN("1234");
$book->setAuthor($rowling);
$book->save();
$this->books[] = $book->getId();
$book = new Book();
$book->setTitle("Harry Potter and the Deathly Hallows");
$book->setISBN("1234");
$book->setAuthor($rowling);
$book->save();
$this->books[] = $book->getId();
}
示例6: testFindOneWithClassAndColumn
public function testFindOneWithClassAndColumn()
{
BookstoreDataPopulator::populate();
BookTableMap::clearInstancePool();
AuthorTableMap::clearInstancePool();
ReviewTableMap::clearInstancePool();
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
$c->setFormatter(ModelCriteria::FORMAT_ON_DEMAND);
$c->filterByTitle('The Tin Drum');
$c->join('Propel\\Tests\\Bookstore\\Book.Author');
$c->withColumn('Author.FirstName', 'AuthorName');
$c->withColumn('Author.LastName', 'AuthorName2');
$c->with('Author');
$c->limit(1);
$con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
$books = $c->find($con);
foreach ($books as $book) {
break;
}
$this->assertTrue($book instanceof Book, 'withColumn() do not change the resulting model class');
$this->assertEquals('The Tin Drum', $book->getTitle());
$this->assertTrue($book->getAuthor() instanceof Author, 'ObjectFormatter correctly hydrates with class');
$this->assertEquals('Gunter', $book->getAuthor()->getFirstName(), 'ObjectFormatter correctly hydrates with class');
$this->assertEquals('Gunter', $book->getVirtualColumn('AuthorName'), 'ObjectFormatter adds withColumns as virtual columns');
$this->assertEquals('Grass', $book->getVirtualColumn('AuthorName2'), 'ObjectFormatter correctly hydrates all virtual columns');
}
示例7: testUpdateOneByOne
public function testUpdateOneByOne()
{
$con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
BookstoreDataPopulator::depopulate($con);
BookstoreDataPopulator::populate($con);
// save all books to make sure related objects are also saved - BookstoreDataPopulator keeps some unsaved
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
$books = $c->find();
foreach ($books as $book) {
$book->save();
}
$count = $con->getQueryCount();
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
$nbBooks = $c->update(array('Title' => 'foo'), $con, true);
$this->assertEquals(4, $nbBooks, 'update() returns the number of updated rows');
$this->assertEquals($count + 1 + 4, $con->getQueryCount(), 'update() updates the objects one by one when called with true as last parameter');
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book', 'b');
$c->where('b.Title = ?', 'foo');
$nbBooks = $c->count();
$this->assertEquals(4, $nbBooks, 'update() updates all records by default');
BookstoreDataPopulator::depopulate($con);
BookstoreDataPopulator::populate($con);
// save all books to make sure related objects are also saved - BookstoreDataPopulator keeps some unsaved
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
$books = $c->find();
foreach ($books as $book) {
$book->save();
}
$count = $con->getQueryCount();
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book', 'b');
$c->where('b.Title = ?', 'Don Juan');
$nbBooks = $c->update(array('ISBN' => '3456'), $con, true);
$this->assertEquals(1, $nbBooks, 'update() updates only the records matching the criteria');
$this->assertEquals($count + 1 + 1, $con->getQueryCount(), 'update() updates the objects one by one when called with true as last parameter');
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book', 'b');
$c->where('b.Title = ?', 'Don Juan');
$book = $c->findOne();
$this->assertEquals('3456', $book->getISBN(), 'update() updates only the records matching the criteria');
}
示例8: testToArrayIncludesForeignObjects
public function testToArrayIncludesForeignObjects()
{
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, array(), 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, array(), 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');
}
示例9: testFindPkWithOneToMany
public function testFindPkWithOneToMany()
{
BookstoreDataPopulator::populate();
BookPeer::clearInstancePool();
AuthorPeer::clearInstancePool();
ReviewPeer::clearInstancePool();
$con = Propel::getServiceContainer()->getConnection(BookPeer::DATABASE_NAME);
$book = BookQuery::create()->findOneByTitle('Harry Potter and the Order of the Phoenix', $con);
$pk = $book->getPrimaryKey();
BookPeer::clearInstancePool();
$book = BookQuery::create()->setFormatter(ModelCriteria::FORMAT_ARRAY)->joinWith('Review')->findPk($pk, $con);
$reviews = $book['Reviews'];
$this->assertEquals(2, count($reviews), 'Related objects are correctly hydrated');
}
示例10: testPruneCompositeKey
public function testPruneCompositeKey()
{
BookstoreDataPopulator::depopulate();
BookstoreDataPopulator::populate();
// save all books to make sure related objects are also saved - BookstoreDataPopulator keeps some unsaved
$c = new ModelCriteria('bookstore', '\\Propel\\Tests\\Bookstore\\Book');
$books = $c->find();
foreach ($books as $book) {
$book->save();
}
BookTableMap::clearInstancePool();
$nbBookListRel = BookListRelQuery::create()->prune()->count();
$this->assertEquals(2, $nbBookListRel, 'prune() does nothing when passed a null object');
$testBookListRel = BookListRelQuery::create()->findOne();
$nbBookListRel = BookListRelQuery::create()->prune($testBookListRel)->count();
$this->assertEquals(1, $nbBookListRel, 'prune() removes an object from the result');
}
示例11: testSelectArrayWithColumn
public function testSelectArrayWithColumn()
{
BookstoreDataPopulator::depopulate($this->con);
BookstoreDataPopulator::populate($this->con);
$c = new ModelCriteria('bookstore', '\\Propel\\Tests\\Bookstore\\Book');
$c->join('Book.Author');
$c->withColumn('LOWER(Book.Title)', 'LowercaseTitle');
$c->select(array('LowercaseTitle', 'Book.Title'));
$c->orderBy('Book.Title');
$rows = $c->find($this->con);
$expectedSQL = 'SELECT LOWER(book.TITLE) AS LowercaseTitle, book.TITLE AS "Book.Title" FROM `book` INNER JOIN `author` ON (book.AUTHOR_ID=author.ID) ORDER BY book.TITLE ASC';
$this->assertEquals($expectedSQL, $this->con->getLastExecutedQuery(), 'find() called after select(array) can cope with a column added with withColumn()');
$expectedRows = array(array('LowercaseTitle' => 'don juan', 'Book.Title' => 'Don Juan'), array('LowercaseTitle' => 'harry potter and the order of the phoenix', 'Book.Title' => 'Harry Potter and the Order of the Phoenix'), array('LowercaseTitle' => 'quicksilver', 'Book.Title' => 'Quicksilver'), array('LowercaseTitle' => 'the tin drum', 'Book.Title' => 'The Tin Drum'));
$this->assertEquals(serialize($rows->getData()), serialize($expectedRows), 'find() called after select(array) can cope with a column added with withColumn()');
}
示例12: testFormatOneManyResults
public function testFormatOneManyResults()
{
$con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
BookstoreDataPopulator::populate($con);
$stmt = $con->query('SELECT * FROM book');
$formatter = new OnDemandFormatter();
$formatter->init(new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book'));
$book = $formatter->formatOne($stmt);
$this->assertTrue($book instanceof Book, 'OnDemandFormatter::formatOne() returns a model object');
}
示例13: testSelectArrayPaginate
public function testSelectArrayPaginate()
{
BookstoreDataPopulator::depopulate($this->con);
BookstoreDataPopulator::populate($this->con);
$pager = BookQuery::create()->select(array('Id', 'Title', 'ISBN', 'Price'))->paginate(1, 10, $this->con);
$this->assertInstanceOf('Propel\\Runtime\\Util\\PropelModelPager', $pager);
foreach ($pager as $result) {
$this->assertEquals(array('Id', 'Title', 'ISBN', 'Price'), array_keys($result));
}
}
示例14: testToArrayIncludesForeignObjects
public function testToArrayIncludesForeignObjects()
{
BookstoreDataPopulator::populate();
BookTableMap::clearInstancePool();
AuthorTableMap::clearInstancePool();
PublisherTableMap::clearInstancePool();
$c = new Criteria();
$c->add(BookTableMap::COL_TITLE, 'Don Juan');
$books = BookQuery::create(null, $c)->joinWith('Author')->find();
$book = $books[0];
$arr1 = $book->toArray(TableMap::TYPE_PHPNAME, null, array(), 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');
}
示例15: testFindPkWithOneToMany
public function testFindPkWithOneToMany()
{
BookstoreDataPopulator::populate();
BookTableMap::clearInstancePool();
AuthorTableMap::clearInstancePool();
ReviewTableMap::clearInstancePool();
$con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
$book = BookQuery::create()->findOneByTitle('Harry Potter and the Order of the Phoenix', $con);
$pk = $book->getPrimaryKey();
BookTableMap::clearInstancePool();
$book = BookQuery::create()->joinWith('Review')->findPk($pk, $con);
$count = $con->getQueryCount();
$reviews = $book->getReviews();
$this->assertEquals($count, $con->getQueryCount(), 'with() hydrates the related objects to save a query ');
$this->assertEquals(2, count($reviews), 'Related objects are correctly hydrated');
}