diff --git a/.gitignore b/.gitignore index c268b282..26e7cd0a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -tests/phpunit.xml -tests/temp/*.php -vendor/* +/tests/phpunit.xml +/tests/temp/*.php +/vendor tags +/composer.lock diff --git a/.travis.yml b/.travis.yml index 4b683d92..267a5632 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,12 +7,13 @@ php: - 5.5 - 5.6 - hhvm - + matrix: allow_failures: - php: hhvm - + before_script: - - php bin/vendors.php + - echo 'extension=mongo.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini + - composer install --prefer-dist script: phpunit -c tests diff --git a/README.md b/README.md index 4e1fd427..bb88283d 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ PHPUnit 3.5 or newer is required. To setup and run tests follow these steps: - go to the root directory of components -- run: **php bin/vendors.php** -- run: **phpunit -c tests** +- run: + + composer install + vendor/bin/phpunit -c tests diff --git a/bin/vendors.php b/bin/vendors.php deleted file mode 100644 index 1945fb89..00000000 --- a/bin/vendors.php +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env php - Installing/Updating $name\n"; - - $installDir = VENDOR_PATH.'/'.$name; - if (!is_dir($installDir)) { - system(sprintf('git clone %s %s', $url, $installDir)); - } - - system(sprintf('cd %s && git fetch origin && git reset --hard %s', $installDir, $rev)); -} diff --git a/composer.json b/composer.json index 66841bb0..26e03060 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,12 @@ "require": { "php": ">=5.3.2" }, + "require-dev": { + "symfony/event-dispatcher": "~2.5", + "doctrine/orm": "~2.4", + "doctrine/mongodb-odm": "~1.0@beta", + "phpunit/phpunit": "~4.2" + }, "suggest": { "doctrine/orm" : "to allow usage pagination with Doctrine ORM", @@ -38,7 +44,12 @@ "autoload": { "psr-0": { - "Knp\\Component": "src/" + "Knp\\Component": "src" + } + }, + "autoload-dev": { + "psr-0": { + "Test": "tests" } } } diff --git a/doc/pager/config.md b/doc/pager/config.md new file mode 100644 index 00000000..c085be2c --- /dev/null +++ b/doc/pager/config.md @@ -0,0 +1,37 @@ +## Configuration + + +Some subscribers will take into account some options. +These options can be passed as the 4th argument of `Paginator::paginate()`. + +For example, Doctrine ORM subscriber will generate different sql queries if the `distinct` options changes. + + +The list of existing options are: + +| name | type | default value | subscribers | +| -------------------------- | ------ | ------------- | ----------------------------------------------- | +| wrap-queries | bool | false | orm QuerySubscriber, orm QueryBuilderSubscriber | +| distinct | bool | true | QuerySubscriber, QueryBuilderSubscriber | +| pageParameterName | string | page | SortableSubscriber | +| defaultSortFieldName | string | | SortableSubscriber | +| defaultSortDirection | string | asc | SortableSubscriber | +| sortFieldWhitelist | array | [] | SortableSubscriber | +| sortFieldParameterName | string | sort | SortableSubscriber | +| sortDirectionParameterName | string | sort | SortableSubscriber | +| filterFieldParameterName | string | filterParam | FiltrationSubscriber | +| filterValueParameterName | string | filterValue | FiltrationSubscriber | + + +## Noticeable behaviors of some options + +### `distinct` + +If set to true, will add a distinct sql keyword on orm queries to ensuire unicity of counted results + + +### `wrap-queries` + +If set to true, will take advantage of doctrine 2.3 output walkers by using subqueries to handle composite keys and HAVING queries. +This can considerably impact performances depending on the query and the platform, you will have to consider it at some point. + diff --git a/doc/pager/intro.md b/doc/pager/intro.md index ee283fee..880a6037 100644 --- a/doc/pager/intro.md +++ b/doc/pager/intro.md @@ -29,6 +29,7 @@ Why reinvent the wheel? Can someone me tell what the definition of **wheel** is - Separation of conserns, paginator is responsible for generating the pagination view only, pagination view - for representation purposes. - Does not require initializing specific adapters +- [configurable](config.md) ## Usage examples: diff --git a/doc/pager/usage.md b/doc/pager/usage.md index b1123b7f..e52daacb 100644 --- a/doc/pager/usage.md +++ b/doc/pager/usage.md @@ -4,50 +4,7 @@ This tutorial will cover installation and usage examples. ## Installation -Initially, all what is needed is: - -- >= php5.3.2 -- Symfony **EventDispatcher** component and if you do not have autoloader, I recommend -**ClassLoader** from the same symfony components -- this repository - -Now somewhere in you third party vendor directory download mentioned dependencies: -**Note:** if you are in your project root and you have [git](http://help.github.com/set-up-git-redirect) -installed, **vendor** directory is the location where these components will be installed. - -- run **git clone git://github.com/knplabs/knp-components.git vendor/knp-components** -- run **git clone git://github.com/symfony/EventDispatcher.git vendor/Symfony/Component/EventDispatcher** -- run **git clone git://github.com/symfony/ClassLoader.git vendor/Symfony/Component/ClassLoader** - -To initially autoload these components, you will need to include -**vendor/Symfony/Component/ClassLoader/UniversalClassLoader.php** - -``` php -registerNamespaces(array( - 'Symfony\\Component' => __DIR__.'/vendor', - 'Knp\\Component' => __DIR__.'/vendor/knp-components/src' -)); -$loader->register(); -``` - -Next, usually **index.php** file is the starting point. Lets create it in the same -project root directory as **autoloader.php** - -``` php - * @copyright Copyright (c) 2010 David Abdemoulaie (http://hobodave.com/) * @license http://hobodave.com/license.txt New BSD License + * @deprecated */ class CountWalker extends TreeWalkerAdapter { diff --git a/src/Knp/Component/Pager/Event/Subscriber/Paginate/Doctrine/ORM/Query/LimitSubqueryWalker.php b/src/Knp/Component/Pager/Event/Subscriber/Paginate/Doctrine/ORM/Query/LimitSubqueryWalker.php index 762ed695..a9aa9460 100644 --- a/src/Knp/Component/Pager/Event/Subscriber/Paginate/Doctrine/ORM/Query/LimitSubqueryWalker.php +++ b/src/Knp/Component/Pager/Event/Subscriber/Paginate/Doctrine/ORM/Query/LimitSubqueryWalker.php @@ -14,6 +14,7 @@ * @author David Abdemoulaie * @copyright Copyright (c) 2010 David Abdemoulaie (http://hobodave.com/) * @license http://hobodave.com/license.txt New BSD License + * @deprecated */ namespace Knp\Component\Pager\Event\Subscriber\Paginate\Doctrine\ORM\Query; diff --git a/src/Knp/Component/Pager/Event/Subscriber/Paginate/Doctrine/ORM/Query/WhereInWalker.php b/src/Knp/Component/Pager/Event/Subscriber/Paginate/Doctrine/ORM/Query/WhereInWalker.php index c8f1f460..3c0cd779 100644 --- a/src/Knp/Component/Pager/Event/Subscriber/Paginate/Doctrine/ORM/Query/WhereInWalker.php +++ b/src/Knp/Component/Pager/Event/Subscriber/Paginate/Doctrine/ORM/Query/WhereInWalker.php @@ -39,6 +39,7 @@ * @author David Abdemoulaie * @copyright Copyright (c) 2010 David Abdemoulaie (http://hobodave.com/) * @license http://hobodave.com/license.txt New BSD License + * @deprecated */ class WhereInWalker extends TreeWalkerAdapter { diff --git a/src/Knp/Component/Pager/Event/Subscriber/Paginate/Doctrine/ORM/QuerySubscriber.php b/src/Knp/Component/Pager/Event/Subscriber/Paginate/Doctrine/ORM/QuerySubscriber.php index a74e7076..f193e5c3 100644 --- a/src/Knp/Component/Pager/Event/Subscriber/Paginate/Doctrine/ORM/QuerySubscriber.php +++ b/src/Knp/Component/Pager/Event/Subscriber/Paginate/Doctrine/ORM/QuerySubscriber.php @@ -14,6 +14,9 @@ use Doctrine\ORM\Tools\Pagination\WhereInWalker as DoctrineWhereInWalker; use Doctrine\ORM\Tools\Pagination\LimitSubqueryWalker as DoctrineLimitSubqueryWalker; +/** + * @deprecated see UsesPaginator + **/ class QuerySubscriber implements EventSubscriberInterface { /** diff --git a/src/Knp/Component/Pager/Event/Subscriber/Paginate/Doctrine/ORM/QuerySubscriber/UsesPaginator.php b/src/Knp/Component/Pager/Event/Subscriber/Paginate/Doctrine/ORM/QuerySubscriber/UsesPaginator.php new file mode 100644 index 00000000..c5dfe69d --- /dev/null +++ b/src/Knp/Component/Pager/Event/Subscriber/Paginate/Doctrine/ORM/QuerySubscriber/UsesPaginator.php @@ -0,0 +1,53 @@ +target instanceof Query) { + return; + } + $event->stopPropagation(); + + $useOutputWalkers = false; + if (isset($event->options['wrap-queries'])) { + $useOutputWalkers = $event->options['wrap-queries']; + } + + $event->target + ->setFirstResult($event->getOffset()) + ->setMaxResults($event->getLimit()) + ->setHint(CountWalker::HINT_DISTINCT, $event->options['distinct']) + ; + + $fetchJoinCollection = true; + if ($event->target->hasHint(self::HINT_FETCH_JOIN_COLLECTION)) { + $fetchJoinCollection = $event->target->getHint(self::HINT_FETCH_JOIN_COLLECTION); + } + + $paginator = new Paginator($event->target, $fetchJoinCollection); + $paginator->setUseOutputWalkers($useOutputWalkers); + $event->count = count($paginator); + $event->items = iterator_to_array($paginator); + } + + public static function getSubscribedEvents() + { + return array( + 'knp_pager.items' => array('items', 0) + ); + } +} diff --git a/src/Knp/Component/Pager/Event/Subscriber/Paginate/PaginationSubscriber.php b/src/Knp/Component/Pager/Event/Subscriber/Paginate/PaginationSubscriber.php index 36fd0dc2..820aad59 100644 --- a/src/Knp/Component/Pager/Event/Subscriber/Paginate/PaginationSubscriber.php +++ b/src/Knp/Component/Pager/Event/Subscriber/Paginate/PaginationSubscriber.php @@ -21,6 +21,7 @@ public function before(BeforeEvent $event) // hook all standard subscribers $disp->addSubscriber(new ArraySubscriber); $disp->addSubscriber(new Doctrine\ORM\QueryBuilderSubscriber); + $disp->addSubscriber(new Doctrine\ORM\QuerySubscriber\UsesPaginator); $disp->addSubscriber(new Doctrine\ORM\QuerySubscriber); $disp->addSubscriber(new Doctrine\ODM\MongoDB\QueryBuilderSubscriber); $disp->addSubscriber(new Doctrine\ODM\MongoDB\QuerySubscriber); diff --git a/tests/Test/Pager/Subscriber/Paginate/Doctrine/ODM/MongoDB/GridFsTest.php b/tests/Test/Pager/Subscriber/Paginate/Doctrine/ODM/MongoDB/GridFsTest.php index 06f07ec1..4cfe8b97 100644 --- a/tests/Test/Pager/Subscriber/Paginate/Doctrine/ODM/MongoDB/GridFsTest.php +++ b/tests/Test/Pager/Subscriber/Paginate/Doctrine/ODM/MongoDB/GridFsTest.php @@ -29,7 +29,7 @@ function shouldPaginate() private function populate() { - $mockFile = realpath(TESTS_PATH.'/temp/summer.gif'); + $mockFile = __DIR__.'/summer.gif'; $dm = $this->getMockDocumentManager(); $summer = new Image; $summer->setTitle('summer'); diff --git a/tests/temp/summer.gif b/tests/Test/Pager/Subscriber/Paginate/Doctrine/ODM/MongoDB/summer.gif similarity index 100% rename from tests/temp/summer.gif rename to tests/Test/Pager/Subscriber/Paginate/Doctrine/ODM/MongoDB/summer.gif diff --git a/tests/Test/Pager/Subscriber/Paginate/Doctrine/ORM/AdvancedQueryTest.php b/tests/Test/Pager/Subscriber/Paginate/Doctrine/ORM/AdvancedQueryTest.php index 0ab0234d..bcd2e9fd 100644 --- a/tests/Test/Pager/Subscriber/Paginate/Doctrine/ORM/AdvancedQueryTest.php +++ b/tests/Test/Pager/Subscriber/Paginate/Doctrine/ORM/AdvancedQueryTest.php @@ -55,7 +55,7 @@ function shouldBeAbleToPaginateWithHavingClause() $q = $this->em->createQuery($dql); $q->setHydrationMode(Query::HYDRATE_ARRAY); $p = new Paginator; - $view = $p->paginate($q, 1, 10); + $view = $p->paginate($q, 1, 10, array('wrap-queries' => true)); $this->assertEquals(3, count($view)); } @@ -126,6 +126,27 @@ function shouldBeAbleToPaginateCaseBasedQuery() $this->assertEquals(1, $items[0]['relevance']); } + /** + * @test + */ + function shouldUseOutputWalkersIfHinted() + { + $this->populate(); + + $dql = <<<___SQL + SELECT p, t + FROM Test\Fixture\Entity\Shop\Product p + INNER JOIN p.tags t + GROUP BY p.id + HAVING p.numTags = COUNT(t) +___SQL; + $q = $this->em->createQuery($dql); + $q->setHydrationMode(Query::HYDRATE_ARRAY); + $p = new Paginator; + $view = $p->paginate($q, 1, 10, array('wrap-queries' => true)); + $this->assertEquals(3, count($view)); + } + protected function getUsedEntityFixtures() { return array( diff --git a/tests/Test/Pager/Subscriber/Paginate/Doctrine/ORM/CompositeKeyTest.php b/tests/Test/Pager/Subscriber/Paginate/Doctrine/ORM/CompositeKeyTest.php index caa9e50b..98898360 100644 --- a/tests/Test/Pager/Subscriber/Paginate/Doctrine/ORM/CompositeKeyTest.php +++ b/tests/Test/Pager/Subscriber/Paginate/Doctrine/ORM/CompositeKeyTest.php @@ -5,22 +5,11 @@ use Test\Tool\BaseTestCaseORM; use Knp\Component\Pager\Paginator; use Test\Fixture\Entity\Composite; +use Knp\Component\Pager\Event\Subscriber\Paginate\Doctrine\ORM\QuerySubscriber\UsesPaginator; +use Doctrine\ORM\Query; class CompositeKeyTest extends BaseTestCaseORM { - /** - * @test - * @expectedException Doctrine\ORM\Mapping\MappingException - */ - function shouldNotBeAbleToCountCompositeKeyOnByCountQueryWalker() - { - $p = new Paginator; - $em = $this->getMockSqliteEntityManager(); - - $query = $em->createQuery('SELECT c FROM Test\Fixture\Entity\Composite c'); - $view = $p->paginate($query); - } - /** * @test */ @@ -38,7 +27,8 @@ function shouldBeHandledByQueryHintByPassingCount() ->createQuery('SELECT c FROM Test\Fixture\Entity\Composite c') ->setHint('knp_paginator.count', $count) ; - $view = $p->paginate($query); + $query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, false); + $view = $p->paginate($query, 1, 10, array('wrap-queries' => true)); $items = $view->getItems(); $this->assertEquals(0, count($items)); diff --git a/tests/Test/Pager/Subscriber/Paginate/Doctrine/ORM/QueryTest.php b/tests/Test/Pager/Subscriber/Paginate/Doctrine/ORM/QueryTest.php index baae174e..097f4f8d 100644 --- a/tests/Test/Pager/Subscriber/Paginate/Doctrine/ORM/QueryTest.php +++ b/tests/Test/Pager/Subscriber/Paginate/Doctrine/ORM/QueryTest.php @@ -8,8 +8,8 @@ use Symfony\Component\EventDispatcher\EventDispatcher; use Knp\Component\Pager\Pagination\PaginationInterface; use Knp\Component\Pager\Event\Subscriber\Paginate\Doctrine\ORM\QuerySubscriber; -use Knp\Component\Pager\Event\Subscriber\Paginate\PaginationSubscriber; use Test\Fixture\Entity\Article; +use Test\Mock\PaginationSubscriber; class QueryTest extends BaseTestCaseORM { @@ -21,8 +21,8 @@ function shouldPaginateSimpleDoctrineQuery() $this->populate(); $dispatcher = new EventDispatcher; - $dispatcher->addSubscriber(new QuerySubscriber); - $dispatcher->addSubscriber(new PaginationSubscriber); // pagination view + $dispatcher->addSubscriber(new QuerySubscriber\UsesPaginator); + $dispatcher->addSubscriber(new PaginationSubscriber); $p = new Paginator($dispatcher); $query = $this->em->createQuery('SELECT a FROM Test\Fixture\Entity\Article a'); diff --git a/tests/Test/Pager/Subscriber/Paginate/Doctrine/ORM/QueryTest/UsesPaginatorTest.php b/tests/Test/Pager/Subscriber/Paginate/Doctrine/ORM/QueryTest/UsesPaginatorTest.php new file mode 100644 index 00000000..68fcd7cc --- /dev/null +++ b/tests/Test/Pager/Subscriber/Paginate/Doctrine/ORM/QueryTest/UsesPaginatorTest.php @@ -0,0 +1,133 @@ +populate(); + + $dql = <<<___SQL + SELECT p, t + FROM Test\Fixture\Entity\Shop\Product p + INNER JOIN p.tags t + GROUP BY p.id + HAVING p.numTags = COUNT(t) +___SQL; + $q = $this->em->createQuery($dql); + $q->setHydrationMode(Query::HYDRATE_ARRAY); + $q->setHint(UsesPaginator::HINT_FETCH_JOIN_COLLECTION, true); + $this->startQueryLog(); + $p = new Paginator; + $view = $p->paginate($q, 1, 10, array('wrap-queries' => true)); + $this->assertEquals(3, $this->queryAnalyzer->getNumExecutedQueries()); + $this->assertEquals(3, count($view)); + } + + /** + * @test + */ + function shouldNotUseOutputWalkersByDefault() + { + $this->populate(); + + $dql = <<<___SQL + SELECT p + FROM Test\Fixture\Entity\Shop\Product p + GROUP BY p.id +___SQL; + $q = $this->em->createQuery($dql); + $q->setHint(UsesPaginator::HINT_FETCH_JOIN_COLLECTION, false); + $q->setHydrationMode(Query::HYDRATE_ARRAY); + $this->startQueryLog(); + $p = new Paginator; + $view = $p->paginate($q, 1, 10, array('wrap-queries' => false)); + $this->assertEquals(2, $this->queryAnalyzer->getNumExecutedQueries()); + $this->assertEquals(3, count($view)); + } + + /** + * @test + */ + function shouldFetchJoinCollectionsIfNeeded() + { + $this->populate(); + + $dql = <<<___SQL + SELECT p, t + FROM Test\Fixture\Entity\Shop\Product p + INNER JOIN p.tags t + GROUP BY p.id + HAVING p.numTags = COUNT(t) +___SQL; + $q = $this->em->createQuery($dql); + $q->setHydrationMode(Query::HYDRATE_ARRAY); + $q->setHint(UsesPaginator::HINT_FETCH_JOIN_COLLECTION, true); + $this->startQueryLog(); + $p = new Paginator; + $view = $p->paginate($q, 1, 10, array('wrap-queries' => true)); + $this->assertEquals(3, $this->queryAnalyzer->getNumExecutedQueries()); + $this->assertEquals(3, count($view)); + } + + protected function getUsedEntityFixtures() + { + return array( + 'Test\Fixture\Entity\Shop\Product', + 'Test\Fixture\Entity\Shop\Tag' + ); + } + + private function populate() + { + $em = $this->getMockSqliteEntityManager(); + $cheep = new Tag; + $cheep->setName('Cheep'); + + $new = new Tag; + $new->setName('New'); + + $special = new Tag; + $special->setName('Special'); + + $starship = new Product; + $starship->setTitle('Starship'); + $starship->setPrice(277.66); + $starship->addTag($new); + $starship->addTag($special); + + $cheese = new Product; + $cheese->setTitle('Cheese'); + $cheese->setPrice(7.66); + $cheese->addTag($cheep); + + $shoe = new Product; + $shoe->setTitle('Shoe'); + $shoe->setPrice(2.66); + $shoe->addTag($special); + + $em->persist($special); + $em->persist($cheep); + $em->persist($new); + $em->persist($starship); + $em->persist($cheese); + $em->persist($shoe); + $em->flush(); + } +} diff --git a/tests/Test/Pager/Subscriber/Sortable/Doctrine/ORM/QueryTest.php b/tests/Test/Pager/Subscriber/Sortable/Doctrine/ORM/QueryTest.php index affbc9e2..97174b03 100644 --- a/tests/Test/Pager/Subscriber/Sortable/Doctrine/ORM/QueryTest.php +++ b/tests/Test/Pager/Subscriber/Sortable/Doctrine/ORM/QueryTest.php @@ -11,6 +11,7 @@ use Knp\Component\Pager\Event\Subscriber\Paginate\PaginationSubscriber; use Knp\Component\Pager\Event\Subscriber\Sortable\Doctrine\ORM\QuerySubscriber as Sortable; use Test\Fixture\Entity\Article; +use Knp\Component\Pager\Event\Subscriber\Paginate\Doctrine\ORM\QuerySubscriber\UsesPaginator; class QueryTest extends BaseTestCaseORM { @@ -73,6 +74,7 @@ function shouldSortSimpleDoctrineQuery() $_GET['direction'] = 'asc'; $this->startQueryLog(); $query = $this->em->createQuery('SELECT a FROM Test\Fixture\Entity\Article a'); + $query->setHint(UsesPaginator::HINT_FETCH_JOIN_COLLECTION, false); $view = $p->paginate($query, 1, 10); $items = $view->getItems(); @@ -91,10 +93,10 @@ function shouldSortSimpleDoctrineQuery() $this->assertEquals('spring', $items[2]->getTitle()); $this->assertEquals('autumn', $items[3]->getTitle()); - $this->assertEquals(6, $this->queryAnalyzer->getNumExecutedQueries()); + $this->assertEquals(4, $this->queryAnalyzer->getNumExecutedQueries()); $executed = $this->queryAnalyzer->getExecutedQueries(); - $this->assertEquals('SELECT DISTINCT a0_.id AS id0, a0_.title AS title1 FROM Article a0_ ORDER BY a0_.title ASC LIMIT 10 OFFSET 0', $executed[1]); - $this->assertEquals('SELECT DISTINCT a0_.id AS id0, a0_.title AS title1 FROM Article a0_ ORDER BY a0_.title DESC LIMIT 10 OFFSET 0', $executed[4]); + $this->assertEquals('SELECT a0_.id AS id0, a0_.title AS title1 FROM Article a0_ ORDER BY a0_.title ASC LIMIT 10 OFFSET 0', $executed[1]); + $this->assertEquals('SELECT a0_.id AS id0, a0_.title AS title1 FROM Article a0_ ORDER BY a0_.title DESC LIMIT 10 OFFSET 0', $executed[3]); } /** @@ -129,6 +131,7 @@ function shouldSortByAnyAvailableAlias() FROM Test\Fixture\Entity\Article a ___SQL; $query = $this->em->createQuery($dql); + $query->setHint(UsesPaginator::HINT_FETCH_JOIN_COLLECTION, false); $p = new Paginator; $this->startQueryLog(); @@ -152,15 +155,16 @@ function shouldWorkWithInitialPaginatorEventDispatcher() ->em ->createQuery('SELECT a FROM Test\Fixture\Entity\Article a') ; + $query->setHint(UsesPaginator::HINT_FETCH_JOIN_COLLECTION, false); $p = new Paginator; $this->startQueryLog(); $view = $p->paginate($query, 1, 10); $this->assertTrue($view instanceof SlidingPagination); - $this->assertEquals(3, $this->queryAnalyzer->getNumExecutedQueries()); + $this->assertEquals(2, $this->queryAnalyzer->getNumExecutedQueries()); $executed = $this->queryAnalyzer->getExecutedQueries(); - $this->assertEquals('SELECT DISTINCT a0_.id AS id0, a0_.title AS title1 FROM Article a0_ ORDER BY a0_.title ASC LIMIT 10 OFFSET 0', $executed[1]); + $this->assertEquals('SELECT a0_.id AS id0, a0_.title AS title1 FROM Article a0_ ORDER BY a0_.title ASC LIMIT 10 OFFSET 0', $executed[1]); } /** @@ -180,7 +184,7 @@ function shouldNotExecuteExtraQueriesWhenCountIsZero() $view = $p->paginate($query, 1, 10); $this->assertTrue($view instanceof SlidingPagination); - $this->assertEquals(1, $this->queryAnalyzer->getNumExecutedQueries()); + $this->assertEquals(2, $this->queryAnalyzer->getNumExecutedQueries()); } protected function getUsedEntityFixtures() diff --git a/tests/Test/Tool/BaseTestCaseMongoODM.php b/tests/Test/Tool/BaseTestCaseMongoODM.php index 01eab91e..cf11d631 100644 --- a/tests/Test/Tool/BaseTestCaseMongoODM.php +++ b/tests/Test/Tool/BaseTestCaseMongoODM.php @@ -23,7 +23,7 @@ abstract class BaseTestCaseMongoODM extends \PHPUnit_Framework_TestCase */ protected function setUp() { - if (!class_exists('Mongo')) { + if (!class_exists('MongoClient')) { $this->markTestSkipped('Missing Mongo extension.'); } } diff --git a/tests/Test/Tool/QueryAnalyzer.php b/tests/Test/Tool/QueryAnalyzer.php index c65858e2..c079bc81 100644 --- a/tests/Test/Tool/QueryAnalyzer.php +++ b/tests/Test/Tool/QueryAnalyzer.php @@ -193,7 +193,7 @@ private function generateSql($sql, $params, $types) if (is_int(key($params))) { $index = key($converted); $sql = preg_replace_callback('@\?@sm', function($match) use (&$index, $converted) { - return $converted[$index++]; + return implode(' ', $converted[$index++]); }, $sql); } else { foreach ($converted as $key => $value) { @@ -239,4 +239,4 @@ private function getConvertedParams($params, $types) } return $result; } -} \ No newline at end of file +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 2ca5a637..57f7600f 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,49 +1,8 @@ registerNamespaces(array( - 'Symfony' => VENDOR_PATH, - 'Knp' => __DIR__.'/../src', - 'Test' => __DIR__, - 'Doctrine\\Common' => VENDOR_PATH.'/doctrine-common/lib', - 'Doctrine\\DBAL' => VENDOR_PATH.'/doctrine-dbal/lib', - 'Doctrine\\ORM' => VENDOR_PATH.'/doctrine-orm/lib', - 'Doctrine\\MongoDB' => VENDOR_PATH.'/doctrine-mongodb/lib', - 'Doctrine\\ODM\\MongoDB' => VENDOR_PATH.'/doctrine-mongodb-odm/lib', -)); -$loader->register(); - -\Doctrine\Common\Annotations\AnnotationRegistry::registerFile( - VENDOR_PATH.'/doctrine-orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php' -); - -\Doctrine\Common\Annotations\AnnotationRegistry::registerFile( - VENDOR_PATH.'/doctrine-mongodb-odm/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/DoctrineAnnotations.php' -); +require __DIR__.'/../vendor/autoload.php'; +\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader('class_exists'); $reader = new \Doctrine\Common\Annotations\AnnotationReader(); $reader = new \Doctrine\Common\Annotations\CachedReader($reader, new \Doctrine\Common\Cache\ArrayCache()); $_ENV['annotation_reader'] = $reader;