This repository has been archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
/
FilterCompositeTest.php
95 lines (87 loc) · 2.56 KB
/
FilterCompositeTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/**
* @see https://github.com/zendframework/zend-hydrator for the canonical source repository
* @copyright Copyright (c) 2010-2018 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-hydrator/blob/master/LICENSE.md New BSD License
*/
declare(strict_types=1);
namespace ZendTest\Hydrator\Filter;
use PHPUnit\Framework\TestCase;
use Zend\Hydrator\Filter\FilterComposite;
use Zend\Hydrator\Exception\InvalidArgumentException;
use Zend\Hydrator\Filter\GetFilter;
use Zend\Hydrator\Filter\HasFilter;
use Zend\Hydrator\Filter\IsFilter;
use Zend\Hydrator\Filter\NumberOfParameterFilter;
/**
* Unit tests for {@see FilterComposite}
*
* @covers \Zend\Hydrator\Filter\FilterComposite
*/
class FilterCompositeTest extends TestCase
{
/**
* @dataProvider getDataProvider
*/
public function testFilters($orFilters, $andFilters, $exceptionThrown)
{
if ($exceptionThrown) {
if (empty($orFilters)) {
$key = 'bar';
} else {
$key = 'foo';
}
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage(
sprintf(
'The value of %s should be either a callable or an ' .
'instance of Zend\Hydrator\Filter\FilterInterface',
$key
)
);
}
$filter = new FilterComposite($orFilters, $andFilters);
foreach ($orFilters as $name => $value) {
$this->assertTrue($filter->hasFilter($name));
}
}
/**
* @return array
*/
public function getDataProvider()
{
return [
[
['foo' => 'bar'],
[],
'exception' => true,
],
[
[],
['bar' => 'foo'],
'exception' => true,
],
[
['foo' => ''],
['bar' => ''],
'exception' => true,
],
[
['foo' => new HasFilter()],
['bar' => new GetFilter()],
'exception' => false,
],
[
[
'foo1' => new HasFilter(),
'foo2' => new IsFilter(),
],
[
'bar1' => new GetFilter(),
'bar2' => new NumberOfParameterFilter(),
],
'exception' => false,
],
];
}
}