|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Graze\ArrayFilter\Test\Integration; |
|
4
|
|
|
|
|
5
|
|
|
use Graze\ArrayFilter\AllOfFilter; |
|
6
|
|
|
use Graze\ArrayFilter\ClosureFilter; |
|
7
|
|
|
use Graze\ArrayFilter\Test\TestCase; |
|
8
|
|
|
use Respect\Validation\Validator as v; |
|
9
|
|
|
|
|
10
|
|
|
class RespectValidationTest extends TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
public function testClosureFilterWithValidator() |
|
13
|
|
|
{ |
|
14
|
|
|
$filter = new ClosureFilter('test', v::stringType()); |
|
15
|
|
|
static::assertTrue($filter->matches(['test' => 'is a string'])); |
|
16
|
|
|
static::assertFalse($filter->matches(['test' => 2.4])); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function testRespectValidatorsAreCallable() |
|
20
|
|
|
{ |
|
21
|
|
|
$filter = v::key('cake', v::stringType()); |
|
22
|
|
|
static::assertTrue($filter(['cake' => 'a string'])); |
|
23
|
|
|
static::assertTrue($filter(['cake' => 'a string', 'other'])); |
|
24
|
|
|
static::assertFalse($filter(['cake' => 12])); |
|
25
|
|
|
static::assertFalse($filter([])); |
|
26
|
|
|
static::assertFalse($filter(['other'])); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function testValidatorWithFilterGroups() |
|
30
|
|
|
{ |
|
31
|
|
|
$allOfFilter = new AllOfFilter([ |
|
32
|
|
|
new ClosureFilter('name', v::intVal()), |
|
33
|
|
|
v::key('key', v::regex('/test.+/i')), |
|
34
|
|
|
]); |
|
35
|
|
|
|
|
36
|
|
|
static::assertTrue($allOfFilter->matches(['name' => '1234', 'key' => 'test47382'])); |
|
37
|
|
|
static::assertFalse($allOfFilter->matches(['name' => 'test', 'key' => 'test47382'])); |
|
38
|
|
|
static::assertFalse($allOfFilter->matches(['name' => '1234', 'key' => 'test'])); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|