ValidatorTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A tearDown() 0 4 1
A itShouldGetIntegerClass() 0 7 1
A itShouldGetFloatClass() 0 7 1
A itShouldGetArrayClass() 0 7 1
A itShouldGetObjectClass() 0 7 1
A itShouldThrowExceptionIfLanguageFileNotFound() 0 8 1
A itShouldThrowRuntimeExceptionIfFunctionMapIsNotFound() 0 14 1
1
<?php
2
3
namespace tests\NilPortugues\Validator;
4
5
use NilPortugues\Validator\Validator;
6
7
/**
8
 * Class ValidatorTest
9
 * @package tests\NilPortugues\Validator
10
 */
11
class ValidatorTest extends \PHPUnit_Framework_TestCase
12
{
13
    /**
14
     * @var Validator
15
     */
16
    private $validator;
17
18
    /**
19
     *
20
     */
21
    public function setUp()
22
    {
23
        $this->validator = Validator::create();
24
    }
25
26
    /**
27
     *
28
     */
29
    public function tearDown()
30
    {
31
        $this->validator = null;
32
    }
33
34
    /**
35
     * @test
36
     */
37
    public function itShouldGetIntegerClass()
38
    {
39
        $this->assertSame(
40
            'NilPortugues\Validator\Attribute\Numeric\IntegerAttribute',
41
            \get_class($this->validator->isInteger('propertyName'))
42
        );
43
    }
44
45
    /**
46
     * @test
47
     */
48
    public function itShouldGetFloatClass()
49
    {
50
        $this->assertSame(
51
            'NilPortugues\Validator\Attribute\Numeric\FloatAttribute',
52
            \get_class($this->validator->isFloat('propertyName'))
53
        );
54
    }
55
56
    /**
57
     * @test
58
     */
59
    public function itShouldGetArrayClass()
60
    {
61
        $this->assertSame(
62
            'NilPortugues\Validator\Attribute\Collection\CollectionAttribute',
63
            \get_class($this->validator->isArray('propertyName'))
64
        );
65
    }
66
67
    /**
68
     * @test
69
     */
70
    public function itShouldGetObjectClass()
71
    {
72
        $this->assertSame(
73
            'NilPortugues\Validator\Attribute\Object\ObjectAttribute',
74
            \get_class($this->validator->isObject('propertyName'))
75
        );
76
    }
77
78
79
    /**
80
     * @test
81
     */
82
    public function itShouldThrowExceptionIfLanguageFileNotFound()
83
    {
84
        $this->setExpectedException('\InvalidArgumentException');
85
        $validator = Validator::create('locale.php');
86
87
        $stringValidator = $validator->isString('property');
88
        $stringValidator->isBetween(500, 1000)->validate('a');
89
    }
90
91
    /**
92
     * @test
93
     */
94
    public function itShouldThrowRuntimeExceptionIfFunctionMapIsNotFound()
95
    {
96
        $validator  = Validator::create();
97
        $reflection = new \ReflectionObject($validator);
98
99
        $property = $reflection->getProperty("functionMapFile");
100
        $property->setAccessible(true);
101
        $property->setValue($validator, 'notFound.php');
102
103
        $this->setExpectedException('\RuntimeException');
104
        $method = $reflection->getMethod('buildFunctionMap');
105
        $method->setAccessible(true);
106
        $method->invoke($validator);
107
    }
108
}
109