RespectValidationTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 4
dl 0
loc 31
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testClosureFilterWithValidator() 0 6 1
A testRespectValidatorsAreCallable() 0 9 1
A testValidatorWithFilterGroups() 0 11 1
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