-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from inovia-team/public-query-filter
Update visibility of 'applyQueryFilters' method
- Loading branch information
Showing
3 changed files
with
183 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,201 @@ | ||
<?php | ||
/** | ||
* @author Matters Studio (https://matters.tech) | ||
*/ | ||
|
||
namespace Matters; | ||
|
||
use Matters\Enums\FilterType; | ||
use Matters\ValueObjects\QueryFilter; | ||
use Mockery as m; | ||
use PHPUnit\Framework\TestCase; | ||
use Zend\Db\Sql\Where; | ||
use Zend\Db\TableGateway\TableGateway; | ||
|
||
|
||
/** | ||
* Class RepositoryTest | ||
* @package Matters | ||
*/ | ||
class RepositoryTest extends TestCase | ||
{ | ||
/** | ||
* @var Repository | ||
*/ | ||
private $testedInstance; | ||
|
||
/** | ||
* @var m\MockInterface | ||
*/ | ||
private $tableGateway; | ||
|
||
protected function setUp() | ||
{ | ||
$this->tableGateway = $this->prophesize(TableGateway::class); | ||
$this->tableGateway = m::mock(TableGateway::class); | ||
|
||
$this->testedInstance = new class($this->tableGateway->reveal()) extends Repository {}; | ||
$this->testedInstance = new class($this->tableGateway) extends Repository {}; | ||
} | ||
|
||
public function testInstance() | ||
{ | ||
self::assertInstanceOf(Repository::class, $this->testedInstance); | ||
} | ||
} | ||
|
||
public function applyQueryFiltersProvider() | ||
{ | ||
return [ | ||
[ | ||
[], | ||
[ | ||
'equal-to-nb-calls' => 0, | ||
'greater-than-nb-calls' => 0, | ||
'greater-than-or-equal-to-nb-calls' => 0, | ||
'less-than-nb-calls' => 0, | ||
'less-than-or-equal-to-nb-calls' => 0, | ||
'like-nb-calls' => 0, | ||
], | ||
], | ||
[ | ||
[ | ||
new QueryFilter('key', FilterType::EQUAL_TO, 'value'), | ||
], | ||
[ | ||
'equal-to-nb-calls' => 1, | ||
'greater-than-nb-calls' => 0, | ||
'greater-than-or-equal-to-nb-calls' => 0, | ||
'less-than-nb-calls' => 0, | ||
'less-than-or-equal-to-nb-calls' => 0, | ||
'like-nb-calls' => 0, | ||
], | ||
], | ||
[ | ||
[ | ||
new QueryFilter('key', FilterType::GREATER_THAN, 'value'), | ||
], | ||
[ | ||
'equal-to-nb-calls' => 0, | ||
'greater-than-nb-calls' => 1, | ||
'greater-than-or-equal-to-nb-calls' => 0, | ||
'less-than-nb-calls' => 0, | ||
'less-than-or-equal-to-nb-calls' => 0, | ||
'like-nb-calls' => 0, | ||
], | ||
], | ||
[ | ||
[ | ||
new QueryFilter('key', FilterType::GREATER_THAN_OR_EQUAL_TO, 'value'), | ||
], | ||
[ | ||
'equal-to-nb-calls' => 0, | ||
'greater-than-nb-calls' => 0, | ||
'greater-than-or-equal-to-nb-calls' => 1, | ||
'less-than-nb-calls' => 0, | ||
'less-than-or-equal-to-nb-calls' => 0, | ||
'like-nb-calls' => 0, | ||
], | ||
], | ||
[ | ||
[ | ||
new QueryFilter('key', FilterType::LESS_THAN, 'value'), | ||
], | ||
[ | ||
'equal-to-nb-calls' => 0, | ||
'greater-than-nb-calls' => 0, | ||
'greater-than-or-equal-to-nb-calls' => 0, | ||
'less-than-nb-calls' => 1, | ||
'less-than-or-equal-to-nb-calls' => 0, | ||
'like-nb-calls' => 0, | ||
], | ||
], | ||
[ | ||
[ | ||
new QueryFilter('key', FilterType::LESS_THAN_OR_EQUAL_TO, 'value'), | ||
], | ||
[ | ||
'equal-to-nb-calls' => 0, | ||
'greater-than-nb-calls' => 0, | ||
'greater-than-or-equal-to-nb-calls' => 0, | ||
'less-than-nb-calls' => 0, | ||
'less-than-or-equal-to-nb-calls' => 1, | ||
'like-nb-calls' => 0, | ||
], | ||
], | ||
[ | ||
[ | ||
new QueryFilter('key', FilterType::LIKE, 'value'), | ||
], | ||
[ | ||
'equal-to-nb-calls' => 0, | ||
'greater-than-nb-calls' => 0, | ||
'greater-than-or-equal-to-nb-calls' => 0, | ||
'less-than-nb-calls' => 0, | ||
'less-than-or-equal-to-nb-calls' => 0, | ||
'like-nb-calls' => 1, | ||
], | ||
], | ||
[ | ||
[ | ||
new QueryFilter('key', FilterType::EQUAL_TO, 'value'), | ||
new QueryFilter('key', FilterType::GREATER_THAN, 'value'), | ||
], | ||
[ | ||
'equal-to-nb-calls' => 1, | ||
'greater-than-nb-calls' => 1, | ||
'greater-than-or-equal-to-nb-calls' => 0, | ||
'less-than-nb-calls' => 0, | ||
'less-than-or-equal-to-nb-calls' => 0, | ||
'like-nb-calls' => 0, | ||
], | ||
], | ||
[ | ||
[ | ||
new QueryFilter('key', FilterType::LESS_THAN, 'value'), | ||
new QueryFilter('key', FilterType::LIKE, 'value'), | ||
], | ||
[ | ||
'equal-to-nb-calls' => 0, | ||
'greater-than-nb-calls' => 0, | ||
'greater-than-or-equal-to-nb-calls' => 0, | ||
'less-than-nb-calls' => 1, | ||
'less-than-or-equal-to-nb-calls' => 0, | ||
'like-nb-calls' => 1, | ||
], | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider applyQueryFiltersProvider | ||
* @param array $filters | ||
* @param array $nbCalls | ||
*/ | ||
public function testApplyQueryFilters(array $filters, array $nbCalls) | ||
{ | ||
$where = m::mock(Where::class); | ||
$where | ||
->shouldReceive('equalTo') | ||
->with('key', 'value') | ||
->times($nbCalls['equal-to-nb-calls']); | ||
$where | ||
->shouldReceive('greaterThan') | ||
->with('key', 'value') | ||
->times($nbCalls['greater-than-nb-calls']); | ||
$where | ||
->shouldReceive('greaterThanOrEqualTo') | ||
->with('key', 'value') | ||
->times($nbCalls['greater-than-or-equal-to-nb-calls']); | ||
$where | ||
->shouldReceive('lessThan') | ||
->with('key', 'value') | ||
->times($nbCalls['less-than-nb-calls']); | ||
$where | ||
->shouldReceive('lessThanOrEqualTo') | ||
->with('key', 'value') | ||
->times($nbCalls['less-than-or-equal-to-nb-calls']); | ||
$where | ||
->shouldReceive('like') | ||
->with('key', '%value%') | ||
->times($nbCalls['like-nb-calls']); | ||
|
||
self::assertSame($where, $this->testedInstance->applyQueryFilters($where, $filters)); | ||
} | ||
} |