From af7380516f72181b058f7f696705c6bfeaad718f Mon Sep 17 00:00:00 2001 From: Marc Morera Date: Fri, 18 Nov 2016 15:54:24 +0100 Subject: [PATCH] Fixed #99 - As well fixed #80 (Same issue) --- .../Paginator/PaginatorWheresEvaluator.php | 7 ++-- .../FakeBundle/Controller/FakeController.php | 34 +++++++++++++++++-- .../PaginatorAnnotationResolverTest.php | 19 +++++++++-- 3 files changed, 52 insertions(+), 8 deletions(-) diff --git a/Resolver/Paginator/PaginatorWheresEvaluator.php b/Resolver/Paginator/PaginatorWheresEvaluator.php index 38208d8..542c615 100644 --- a/Resolver/Paginator/PaginatorWheresEvaluator.php +++ b/Resolver/Paginator/PaginatorWheresEvaluator.php @@ -107,12 +107,11 @@ private function clearWildcards($where) */ private function addWildcards($annotationWhereParameter, $whereValue) { - $hasInitialPercentage = (strpos($annotationWhereParameter, '%') === 0); - $hasEndPercentage = (strpos($annotationWhereParameter, '%') === 0); - if ($hasInitialPercentage) { + if (substr($annotationWhereParameter, 0, 1) === '%') { $whereValue = '%' . $whereValue; } - if ($hasEndPercentage) { + + if (substr($annotationWhereParameter, -1, 1) === '%') { $whereValue = $whereValue . '%'; } diff --git a/Tests/FakeBundle/Controller/FakeController.php b/Tests/FakeBundle/Controller/FakeController.php index 5833a3a..cfc6a4b 100644 --- a/Tests/FakeBundle/Controller/FakeController.php +++ b/Tests/FakeBundle/Controller/FakeController.php @@ -386,6 +386,7 @@ public function paginatorNotMatchingAction(Paginator $paginator) * Public pagination method. * * @\Mmoreram\ControllerExtraBundle\Annotation\Paginator( + * name = "paginator", * class = { * "factory" = "Mmoreram\ControllerExtraBundle\Tests\FakeBundle\Factory\FakeFactory", * "method" = "createNonStatic", @@ -396,12 +397,41 @@ public function paginatorNotMatchingAction(Paginator $paginator) * } * ) * + * @\Mmoreram\ControllerExtraBundle\Annotation\Paginator( + * name = "paginatorPartial1", + * class = { + * "factory" = "Mmoreram\ControllerExtraBundle\Tests\FakeBundle\Factory\FakeFactory", + * "method" = "createNonStatic", + * "static" = false + * }, + * wheres = { + * { "x", "field" , "LIKE", "?search1?%" } + * } + * ) + * + * @\Mmoreram\ControllerExtraBundle\Annotation\Paginator( + * name = "paginatorPartial2", + * class = { + * "factory" = "Mmoreram\ControllerExtraBundle\Tests\FakeBundle\Factory\FakeFactory", + * "method" = "createNonStatic", + * "static" = false + * }, + * wheres = { + * { "x", "field" , "LIKE", "%?search2?" } + * } + * ) + * * @\Mmoreram\ControllerExtraBundle\Annotation\JsonResponse() */ - public function PaginatorLikeWithGetParameterAction(Paginator $paginator) - { + public function PaginatorLikeWithGetParameterAction( + Paginator $paginator, + Paginator $paginatorPartial1, + Paginator $paginatorPartial2 + ) { return [ 'count' => $paginator->getIterator()->count(), + 'count1' => $paginatorPartial1->getIterator()->count(), + 'count2' => $paginatorPartial2->getIterator()->count(), ]; } diff --git a/Tests/Functional/Resolver/PaginatorAnnotationResolverTest.php b/Tests/Functional/Resolver/PaginatorAnnotationResolverTest.php index 5d2d584..29b9932 100644 --- a/Tests/Functional/Resolver/PaginatorAnnotationResolverTest.php +++ b/Tests/Functional/Resolver/PaginatorAnnotationResolverTest.php @@ -360,11 +360,26 @@ public function testPaginatorWithLikeWithGetParameterAnnotation() ->client ->request( 'GET', - '/fake/paginator/likewithgetparameter?search=test' + '/fake/paginator/likewithgetparameter?search=test&search1=we&search2=paginator' ); $this->assertEquals( - '{"count":1}', + '{"count":1,"count1":1,"count2":1}', + $this + ->client + ->getResponse() + ->getContent() + ); + + $this + ->client + ->request( + 'GET', + '/fake/paginator/likewithgetparameter?search=house&search1=Test&search2=Test' + ); + + $this->assertEquals( + '{"count":0,"count1":0,"count2":0}', $this ->client ->getResponse()