当前位置: 首页>>代码示例>>PHP>>正文


PHP Bookstore\BookQuery类代码示例

本文整理汇总了PHP中Propel\Tests\Bookstore\BookQuery的典型用法代码示例。如果您正苦于以下问题:PHP BookQuery类的具体用法?PHP BookQuery怎么用?PHP BookQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BookQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testFrom

 public function testFrom()
 {
     $q = PropelQuery::from('\\Propel\\Tests\\Bookstore\\Book');
     $expected = new BookQuery();
     $this->assertEquals($expected, $q, 'from() returns a Model query instance based on the model name');
     $q = PropelQuery::from('\\Propel\\Tests\\Bookstore\\Book b');
     $expected = new BookQuery();
     $expected->setModelAlias('b');
     $this->assertEquals($expected, $q, 'from() sets the model alias if found after the blank');
     $q = PropelQuery::from('\\Propel\\Tests\\Runtime\\Query\\myBook');
     $expected = new myBookQuery();
     $this->assertEquals($expected, $q, 'from() can find custom query classes');
     try {
         $q = PropelQuery::from('Foo');
         $this->fail('PropelQuery::from() throws an exception when called on a non-existing query class');
     } catch (PropelException $e) {
         $this->assertTrue(true, 'PropelQuery::from() throws an exception when called on a non-existing query class');
     }
 }
开发者ID:RafalFilipek,项目名称:Propel2,代码行数:19,代码来源:PropelQueryTest.php

示例2: testSerializeHydratedObject

 public function testSerializeHydratedObject()
 {
     $book = new Book();
     $book->setTitle('Foo3');
     $book->setISBN('1234');
     $book->save();
     BookTableMap::clearInstancePool();
     $book = BookQuery::create()->findOneByTitle('Foo3');
     $sb = serialize($book);
     $this->assertEquals($book, unserialize($sb));
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:11,代码来源:ActiveRecordSerializeTest.php

示例3: testMagicFindByObject

 public function testMagicFindByObject()
 {
     $con = Propel::getServiceContainer()->getConnection(BookPeer::DATABASE_NAME);
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Author');
     $testAuthor = $c->findOne();
     $q = BookQuery::create()->findByAuthor($testAuthor);
     $expectedSQL = "SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID FROM `book` WHERE book.AUTHOR_ID=" . $testAuthor->getId();
     $this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'findByXXX($value) is turned into findBy(XXX, $value)');
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Author');
     $testAuthor = $c->findOne();
     $q = BookQuery::create()->findByAuthorAndISBN($testAuthor, 1234);
     $expectedSQL = "SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID FROM `book` WHERE book.AUTHOR_ID=" . $testAuthor->getId() . " AND book.ISBN=1234";
     $this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'findByXXXAndYYY($value) is turned into findBy(array(XXX, YYY), $value)');
 }
开发者ID:rozwell,项目名称:Propel2,代码行数:14,代码来源:ModelCriteriaTest.php

示例4: testMagicRequireOneWithAndThrowsException

 public function testMagicRequireOneWithAndThrowsException()
 {
     $this->setExpectedException('\\Propel\\Runtime\\Exception\\EntityNotFoundException', 'Book could not be found');
     BookQuery::create()->requireOneByTitleAndId('Not Existing Book', -1337);
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:5,代码来源:ModelCriteriaTest.php

示例5: testDebugLog

 public function testDebugLog()
 {
     $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
     // save data to return to normal state after test
     $logger = $con->getLogger();
     $logMethods = $con->getLogMethods();
     $testLog = new Logger('debug');
     $handler = new LastMessageHandler();
     $testLog->pushHandler($handler);
     $con->setLogger($testLog);
     $con->setLogMethods(['exec', 'query', 'execute', 'beginTransaction', 'commit', 'rollBack']);
     $con->useDebug(true);
     $con->beginTransaction();
     // test transaction log
     $this->assertEquals('Begin transaction', $handler->latestMessage, 'PropelPDO logs begin transaction in debug mode');
     $con->commit();
     $this->assertEquals('Commit transaction', $handler->latestMessage, 'PropelPDO logs commit transaction in debug mode');
     $con->beginTransaction();
     $con->rollBack();
     $this->assertEquals('Rollback transaction', $handler->latestMessage, 'PropelPDO logs rollback transaction in debug mode');
     $con->beginTransaction();
     $handler->latestMessage = '';
     $con->beginTransaction();
     $this->assertEquals('', $handler->latestMessage, 'PropelPDO does not log nested begin transaction in debug mode');
     $con->commit();
     $this->assertEquals('', $handler->latestMessage, 'PropelPDO does not log nested commit transaction in debug mode');
     $con->beginTransaction();
     $con->rollBack();
     $this->assertEquals('', $handler->latestMessage, 'PropelPDO does not log nested rollback transaction in debug mode');
     $con->rollback();
     // test query log
     $con->beginTransaction();
     $c = new Criteria();
     $c->add(BookTableMap::COL_TITLE, 'Harry%s', Criteria::LIKE);
     $books = BookQuery::create(null, $c)->find($con);
     $latestExecutedQuery = $this->getSql("SELECT book.id, book.title, book.isbn, book.price, book.publisher_id, book.author_id FROM book WHERE book.title LIKE 'Harry%s'");
     $this->assertEquals($latestExecutedQuery, $handler->latestMessage, 'PropelPDO logs queries and populates bound parameters in debug mode');
     BookTableMap::doDeleteAll($con);
     $latestExecutedQuery = $this->getSql("DELETE FROM book");
     $this->assertEquals($latestExecutedQuery, $handler->latestMessage, 'PropelPDO logs deletion queries in debug mode');
     $latestExecutedQuery = 'DELETE FROM book WHERE 1=1';
     $con->exec($latestExecutedQuery);
     $this->assertEquals($latestExecutedQuery, $handler->latestMessage, 'PropelPDO logs exec queries in debug mode');
     $con->commit();
     // return to normal state after test
     $con->setLogger($logger);
     $con->setLogMethods($logMethods);
 }
开发者ID:disider,项目名称:Propel2,代码行数:48,代码来源:PropelPDOTest.php

示例6: testGetResultsRespectsFormatter

 public function testGetResultsRespectsFormatter()
 {
     $this->createBooks(5);
     $query = BookQuery::create();
     $query->setFormatter(ModelCriteria::FORMAT_ARRAY);
     $pager = new PropelModelPager($query, 4);
     $pager->setPage(1);
     $pager->init();
     $this->assertTrue($pager->getResults() instanceof ArrayCollection, 'getResults() returns a PropelArrayCollection if the query uses array hydration');
 }
开发者ID:norfil,项目名称:Propel2,代码行数:10,代码来源:PropelModelPagerTest.php

示例7: testGroupBy

 public function testGroupBy()
 {
     $params = array();
     $c = BookQuery::create()->joinReview()->withColumn('COUNT(Review.Id)', 'Count')->groupById();
     $result = $c->createSelectSql($params);
     if ($this->runningOnPostgreSQL()) {
         $sql = 'SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID, COUNT(review.ID) AS Count FROM book LEFT JOIN review ON (book.ID=review.BOOK_ID) GROUP BY book.ID,book.TITLE,book.ISBN,book.PRICE,book.PUBLISHER_ID,book.AUTHOR_ID';
     } else {
         $sql = $this->getSql('SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID, COUNT(review.ID) AS Count FROM `book` LEFT JOIN `review` ON (book.ID=review.BOOK_ID) GROUP BY book.ID');
     }
     $this->assertEquals($sql, $result);
 }
开发者ID:a-melnichuk,项目名称:Movies-Demo,代码行数:12,代码来源:CriteriaTest.php

示例8: testSubQueryCount

 public function testSubQueryCount()
 {
     $subCriteria = new BookQuery();
     $c = new BookQuery();
     $c->addSelectQuery($subCriteria, 'subCriteriaAlias');
     $c->filterByPrice(20, Criteria::LESS_THAN);
     $nbBooks = $c->count();
     $query = Propel::getConnection()->getLastExecutedQuery();
     $sql = $this->getSql("SELECT COUNT(*) FROM (SELECT subCriteriaAlias.id, subCriteriaAlias.title, subCriteriaAlias.isbn, subCriteriaAlias.price, subCriteriaAlias.publisher_id, subCriteriaAlias.author_id FROM (SELECT book.id, book.title, book.isbn, book.price, book.publisher_id, book.author_id FROM book) AS subCriteriaAlias WHERE subCriteriaAlias.price<20) propelmatch4cnt");
     $this->assertEquals($sql, $query, 'addSelectQuery() doCount is defined as complexQuery');
 }
开发者ID:KyleGoslan,项目名称:Huge-Propel,代码行数:11,代码来源:SubQueryTest.php

示例9: testCountableInterface

 public function testCountableInterface()
 {
     BookQuery::create()->deleteAll();
     $pager = $this->getPager(10);
     $this->assertCount(0, $pager);
     $this->createBooks(15);
     $pager = $this->getPager(10);
     $this->assertCount(10, $pager);
     $pager = $this->getPager(10, 2);
     $this->assertCount(5, $pager);
 }
开发者ID:bondarovich,项目名称:Propel2,代码行数:11,代码来源:PropelModelPagerTest.php

示例10: testGroupBy

 public function testGroupBy()
 {
     $params = [];
     $c = BookQuery::create()->joinReview()->withColumn('COUNT(Review.id)', 'Count')->groupById();
     $result = $c->createSelectSql($params);
     if ($this->runningOnPostgreSQL()) {
         $sql = 'SELECT book.id, book.title, book.isbn, book.price, book.publisher_id, book.author_id, COUNT(review.id) AS Count FROM book LEFT JOIN review ON (book.id=review.book_id) GROUP BY book.id,book.title,book.isbn,book.price,book.publisher_id,book.author_id';
     } else {
         $sql = $this->getSql('SELECT book.id, book.title, book.isbn, book.price, book.publisher_id, book.author_id, COUNT(review.id) AS Count FROM book LEFT JOIN review ON (book.id=review.book_id) GROUP BY book.id');
     }
     $this->assertEquals($sql, $result);
 }
开发者ID:naldz,项目名称:cyberden,代码行数:12,代码来源:CriteriaTest.php

示例11: testPopulateRelationManyToOne

 public function testPopulateRelationManyToOne()
 {
     $con = Propel::getServiceContainer()->getReadConnection(BookTableMap::DATABASE_NAME);
     AuthorTableMap::clearInstancePool();
     BookTableMap::clearInstancePool();
     $books = BookQuery::create()->find($con);
     $count = $con->getQueryCount();
     $books->populateRelation('Author', null, $con);
     foreach ($books as $book) {
         $author = $book->getAuthor();
     }
     $this->assertEquals($count + 1, $con->getQueryCount(), 'populateRelation() populates a many-to-one relationship with a single supplementary query');
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:13,代码来源:ObjectCollectionWithFixturesTest.php

示例12: testRemoveObjectOneToManyWithFkRequired

 public function testRemoveObjectOneToManyWithFkRequired()
 {
     BookSummaryQuery::create()->deleteAll();
     BookQuery::create()->deleteAll();
     $bookSummary = new BookSummary();
     $bookSummary->setSummary('summary Propel Book');
     $bookSummary2 = new BookSummary();
     $bookSummary2->setSummary('summary2 Propel Book');
     $book = new Book();
     $book->setTitle('Propel Book');
     $book->setISBN('01234');
     $book->addBookSummary($bookSummary);
     $book->addBookSummary($bookSummary2);
     $this->assertCount(2, $book->getBookSummaries());
     $book->removeBookSummary($bookSummary);
     $bookSummaries = $book->getBookSummaries();
     $this->assertCount(1, $bookSummaries);
     $this->assertEquals('summary2 Propel Book', $bookSummaries->getFirst()->getSummary());
     $book->save();
     $bookSummary2->save();
     $this->assertEquals(1, BookQuery::create()->count(), 'One Book');
     $this->assertEquals(1, BookSummaryQuery::create()->count(), 'One Summary');
     $this->assertEquals(1, BookSummaryQuery::create()->filterBySummarizedBook($book)->count());
     $book->addBookSummary($bookSummary);
     $bookSummary->save();
     $book->save();
     $this->assertEquals(2, BookSummaryQuery::create()->filterBySummarizedBook($book)->count());
     $book->removeBookSummary($bookSummary2);
     $book->save();
     $this->assertEquals(1, BookSummaryQuery::create()->filterBySummarizedBook($book)->count());
     $this->assertEquals(1, BookSummaryQuery::create()->count(), 'One Book summary because FK is required so book summary is deleted when book is saved');
 }
开发者ID:disider,项目名称:Propel2,代码行数:32,代码来源:GeneratedObjectRelTest.php

示例13: testMagicFindByObject

 public function testMagicFindByObject()
 {
     $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Author');
     $testAuthor = $c->findOne();
     $q = BookQuery::create()->findByAuthor($testAuthor);
     $expectedSQL = $this->getSql("SELECT book.id, book.title, book.isbn, book.price, book.publisher_id, book.author_id FROM book WHERE book.author_id=" . $testAuthor->getId());
     $this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'findByXXX($value) is turned into findBy(XXX, $value)');
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Author');
     $testAuthor = $c->findOne();
     $q = BookQuery::create()->findByAuthorAndISBN($testAuthor, 1234);
     $expectedSQL = $this->getSql("SELECT book.id, book.title, book.isbn, book.price, book.publisher_id, book.author_id FROM book WHERE book.author_id=" . $testAuthor->getId() . " AND book.isbn=1234");
     $this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'findByXXXAndYYY($value) is turned into findBy(array(XXX, YYY), $value)');
 }
开发者ID:KyleGoslan,项目名称:Huge-Propel,代码行数:14,代码来源:ModelCriteriaTest.php

示例14: testSetterOneToManyReplacesOldObjectsByNewObjects

 public function testSetterOneToManyReplacesOldObjectsByNewObjects()
 {
     // Ensure no data
     BookQuery::create()->deleteAll();
     AuthorQuery::create()->deleteAll();
     $books = new ObjectCollection();
     foreach (array('foo', 'bar') as $title) {
         $b = new Book();
         $b->setTitle($title);
         $books[] = $b;
     }
     $a = new Author();
     $a->setBooks($books);
     $a->save();
     $books = $a->getBooks();
     $this->assertEquals('foo', $books[0]->getTitle());
     $this->assertEquals('bar', $books[1]->getTitle());
     $books = new ObjectCollection();
     foreach (array('bam', 'bom') as $title) {
         $b = new Book();
         $b->setTitle($title);
         $books[] = $b;
     }
     $a->setBooks($books);
     $a->save();
     $books = $a->getBooks();
     $this->assertEquals('bam', $books[0]->getTitle());
     $this->assertEquals('bom', $books[1]->getTitle());
     $this->assertEquals(1, AuthorQuery::create()->count());
     $this->assertEquals(2, BookQuery::create()->count());
 }
开发者ID:rouffj,项目名称:Propel2,代码行数:31,代码来源:GeneratedObjectTest.php

示例15: testLobSetting_WriteMode

 public function testLobSetting_WriteMode()
 {
     $blob_path = $this->getLobFile('tin_drum.gif');
     $blob2_path = $this->getLobFile('propel.gif');
     $clob_path = $this->getLobFile('tin_drum.txt');
     $book = BookQuery::create()->findOne();
     $m1 = new Media();
     $m1->setBook($book);
     $m1->setCoverImage(file_get_contents($blob_path));
     $m1->setExcerpt(file_get_contents($clob_path));
     $m1->save();
     MediaTableMap::clearInstancePool();
     // make sure we have the latest from the db:
     $m2 = MediaQuery::create()->findPk($m1->getId());
     // now attempt to assign a temporary stream, opened in 'w' mode, to the db
     $stream = fopen("php://memory", 'w');
     fwrite($stream, file_get_contents($blob2_path));
     $m2->setCoverImage($stream);
     $m2->save();
     fclose($stream);
     $m2->reload();
     $this->assertEquals(md5(file_get_contents($blob2_path)), md5(stream_get_contents($m2->getCoverImage())), "Expected contents to match when setting stream w/ 'w' mode");
     $stream2 = fopen("php://memory", 'w+');
     fwrite($stream2, file_get_contents($blob_path));
     rewind($stream2);
     $this->assertEquals(md5(file_get_contents($blob_path)), md5(stream_get_contents($stream2)), "Expecting setup to be correct");
     $m2->setCoverImage($stream2);
     $m2->save();
     $m2->reload();
     $this->assertEquals(md5(file_get_contents($blob_path)), md5(stream_get_contents($m2->getCoverImage())), "Expected contents to match when setting stream w/ 'w+' mode");
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:31,代码来源:GeneratedObjectLobTest.php


注:本文中的Propel\Tests\Bookstore\BookQuery类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。