Skip to content

Commit

Permalink
Add tests for ActionList
Browse files Browse the repository at this point in the history
  • Loading branch information
maldoinc committed Dec 4, 2022
1 parent 71b888f commit f665acb
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ expressions and can be constrained on which entities it should be possible to ex
| `ends_with` | Ends with | `email[ends_with]=@gmail.com` |
| `contains` | Contains | `name[containts]=d` |

\* You can enable treating key=value syntax as an equality operator in the `ActionList` static constructors.
\* By default the `field=value` syntax is off. It can be enabled as an equality operator in the `ActionList`
constructors (`simpleEquality: true`).

### Sorting

Expand Down
44 changes: 44 additions & 0 deletions tests/Doctrine/Filter/Action/ActionListTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace App\Tests\Doctrine\Filter\Action;

use Maldoinc\Doctrine\Filter\Action\ActionList;
use Maldoinc\Doctrine\Filter\Action\FilterAction;
use PHPUnit\Framework\TestCase;

class ActionListTest extends TestCase
{
public function fromQueryStringSimpleEqualityDataProvider(): iterable
{
yield [
'id=5&name=hello&page=3&foo=bar&ignored[maybe]=yes',

// Now that simple equality is enabled we're pulling all sorts of actions, but they will
// be ignored by DoctrineFilter as they are unmapped.
[
new FilterAction('id', 'eq', '5'),
new FilterAction('name', 'eq', 'hello'),
new FilterAction('page', 'eq', '3'),
new FilterAction('foo', 'eq', 'bar'),
new FilterAction('ignored', 'maybe', 'yes'),
],
[],
];
}

/**
* @dataProvider fromQueryStringSimpleEqualityDataProvider
*
* @return void
*/
public function testFromQueryStringSimpleEquality(
string $queryString,
array $expectedFilters,
array $expectedOrderBy
) {
$actionList = ActionList::fromQueryString($queryString, null, true);

$this->assertEquals($expectedFilters, $actionList->getFilterActions());
$this->assertEquals($expectedOrderBy, $actionList->getOrderByActions());
}
}

0 comments on commit f665acb

Please sign in to comment.