Completed
Push — master ( 26941e...2ed0f3 )
by Indra
02:25
created

ValidatorTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
c 1
b 0
f 1
lcom 0
cbo 2
dl 0
loc 57
rs 10
1
<?php
2
3
namespace IndraGunawan\RestService\Tests\Validator;
4
5
use IndraGunawan\RestService\Validator\Validator;
6
7
class ValidatorTest extends \PHPUnit_Framework_TestCase
8
{
9
    public function testValidate()
10
    {
11
        $validator = new Validator();
12
        $validator->add('RestService[email]', ['rule' => 'required | email'], '[email protected]');
13
        $validator->add('RestService[website]', ['rule' => 'url', 'defaultValue' => 'http://example.com'], '');
14
        $validator->isValid();
15
16
        $this->assertEquals(
17
            [
18
                'RestService[email]' => 'required | email',
19
                'RestService[website]' => 'url',
20
            ],
21
            $validator->getRules()
22
        );
23
24
        $this->assertEquals(
25
            [
26
                'RestService[email]' => '[email protected]',
27
                'RestService[website]' => 'http://example.com',
28
            ],
29
            $validator->getDatas()
30
        );
31
    }
32
33
    public function testValidateWithInput()
34
    {
35
        $validator = new Validator();
36
        $validator->add('RestService[email]', ['rule' => 'required | email', 'defaultValue' => '[email protected]'], '');
37
        $validator->add('RestService[website]', ['rule' => 'url', 'defaultValue' => 'http://example.com'], '');
38
        $validator->validate([
39
            'RestService' => [
40
                'email' => '[email protected]',
41
                'website' => '',
42
            ],
43
        ]);
44
45
        $this->assertEquals(
46
            [
47
                'RestService[email]' => 'required | email',
48
                'RestService[website]' => 'url',
49
            ],
50
            $validator->getRules()
51
        );
52
53
        $this->assertEquals(
54
            [
55
                'RestService' => [
56
                    'email' => '[email protected]',
57
                    'website' => '',
58
                ],
59
            ],
60
            $validator->getDatas()
61
        );
62
    }
63
}
64