Skip to content

Commit

Permalink
Merge pull request #101 from mmoreram/fix/fixed-paginator-wildcards
Browse files Browse the repository at this point in the history
Fixed #99
  • Loading branch information
mmoreram authored Nov 18, 2016
2 parents d79de19 + af73805 commit 7fa1e8e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
7 changes: 3 additions & 4 deletions Resolver/Paginator/PaginatorWheresEvaluator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 . '%';
}

Expand Down
34 changes: 32 additions & 2 deletions Tests/FakeBundle/Controller/FakeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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(),
];
}

Expand Down
19 changes: 17 additions & 2 deletions Tests/Functional/Resolver/PaginatorAnnotationResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 7fa1e8e

Please sign in to comment.