ObjectValidationTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

8 Methods

Rating   Name   Duplication   Size   Complexity  
A itShouldCheckIfIsObject() 0 5 1
A itShouldCheckIfIsInstanceOf() 0 6 1
A itShouldCheckIfHasProperty() 0 7 1
A itShouldCheckIfHasMethod() 0 7 1
A itShouldCheckIfHasParentClass() 0 5 1
A itShouldCheckIfIsChildOf() 0 7 1
A itShouldCheckIfInheritsFrom() 0 7 1
A itShouldCheckIfHasInterface() 0 12 1
1
<?php
2
/**
3
 * Author: Nil Portugués Calderó <[email protected]>
4
 * Date: 9/20/14
5
 * Time: 12:03 PM
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Tests\NilPortugues\Validator\Validation\Object;
12
13
use NilPortugues\Validator\Validation\Object\ObjectValidation;
14
use Tests\NilPortugues\Validator\Resources\Dummy;
15
16
/**
17
 * Class ObjectValidationTest
18
 * @package Tests\NilPortugues\Validator\Validation\ObjectAttribute
19
 */
20
class ObjectValidationTest extends \PHPUnit_Framework_TestCase
21
{
22
    /**
23
     * @test
24
     */
25
    public function itShouldCheckIfIsObject()
26
    {
27
        $this->assertTrue(ObjectValidation::isObject(new \stdClass()));
28
        $this->assertFalse(ObjectValidation::isObject('a'));
29
    }
30
31
    /**
32
     * @test
33
     */
34
    public function itShouldCheckIfIsInstanceOf()
35
    {
36
        $this->assertTrue(ObjectValidation::isInstanceOf(new \DateTime(), 'DateTime'));
37
        $this->assertFalse(ObjectValidation::isInstanceOf(new \stdClass(), 'DateTime'));
38
        $this->assertFalse(ObjectValidation::isInstanceOf('a', 'DateTime'));
39
    }
40
41
    /**
42
     * @test
43
     */
44
    public function itShouldCheckIfHasProperty()
45
    {
46
        $dummy = new Dummy();
47
48
        $this->assertTrue(ObjectValidation::hasProperty($dummy, 'userName'));
49
        $this->assertFalse(ObjectValidation::hasProperty($dummy, 'password'));
50
    }
51
52
    /**
53
     * @test
54
     */
55
    public function itShouldCheckIfHasMethod()
56
    {
57
        $dummy = new Dummy();
58
59
        $this->assertTrue(ObjectValidation::hasMethod($dummy, 'getUserName'));
60
        $this->assertFalse(ObjectValidation::hasMethod($dummy, 'getPassword'));
61
    }
62
63
    /**
64
     * @test
65
     */
66
    public function itShouldCheckIfHasParentClass()
67
    {
68
        $this->assertTrue(ObjectValidation::hasParentClass(new Dummy()));
69
        $this->assertFalse(ObjectValidation::hasParentClass(new \stdClass()));
70
    }
71
72
    /**
73
     * @test
74
     */
75
    public function itShouldCheckIfIsChildOf()
76
    {
77
        $dummy = new Dummy();
78
79
        $this->assertTrue(ObjectValidation::isChildOf($dummy, 'DateTime'));
80
        $this->assertFalse(ObjectValidation::isChildOf($dummy, 'DateTimeZone'));
81
    }
82
83
    /**
84
     * @test
85
     */
86
    public function itShouldCheckIfInheritsFrom()
87
    {
88
        $dummy = new Dummy();
89
90
        $this->assertTrue(ObjectValidation::inheritsFrom($dummy, 'DateTime'));
91
        $this->assertFalse(ObjectValidation::inheritsFrom($dummy, 'DateTimeZone'));
92
    }
93
94
    /**
95
     * @test
96
     */
97
    public function itShouldCheckIfHasInterface()
98
    {
99
        $dummy = new Dummy();
100
101
        $this->assertTrue(
102
            ObjectValidation::hasInterface(
103
                $dummy,
104
                'Tests\NilPortugues\Validator\Resources\DummyInterface'
105
            )
106
        );
107
        $this->assertFalse(ObjectValidation::inheritsFrom($dummy, 'DateTimeZone'));
108
    }
109
}
110