Passed
Branch master (94149a)
by Alexander
02:22
created

IntersectTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 87
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testIntersection() 0 54 1
A testEmptyIntersect() 0 13 1
A testDifferentElements() 0 6 1
A testOne() 0 8 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: horat1us
5
 * Date: 5/4/17
6
 * Time: 11:35 AM
7
 */
8
9
namespace Horat1us\Tests;
10
11
12
use Horat1us\Examples\Head;
13
use Horat1us\Examples\Person;
14
use Horat1us\XmlConvertibleObject;
15
16
class IntersectTest extends \PHPUnit_Framework_TestCase
17
{
18
    public function testIntersection()
19
    {
20
        $xml = new Person("Alex", "Letni", [
21
            new Head("small", null, [
22
                new XmlConvertibleObject('Eye'),
23
                new XmlConvertibleObject('Eye', [
24
                    new Person('Adam', 'Morgan'),
25
                ]),
26
            ])
27
        ]);
28
29
        $compared = new Person("Alex", "Letni", [
30
            new Head('small', null, [
31
                new XmlConvertibleObject('Eye', [
32
                    new Person('Adam', 'Morgan'),
33
                ]),
34
            ])
35
        ]);
36
37
38
        $result = $xml->xmlIntersect($compared);
39
        $this->assertInstanceOf(Person::class, $result);
40
        /** @var Person $result */
41
42
        $this->assertEquals($result->name, $compared->name);
43
        $this->assertEquals($result->name, $xml->name);
44
        $this->assertNotNull($result->xmlChildren);
45
        $this->assertCount(1, $result->xmlChildren);
46
        $this->assertInstanceOf(Head::class, $result->xmlChildren[0]);
47
        $this->assertNotNull($result->xmlChildren[0]->xmlChildren);
48
        $this->assertCount(1, $result->xmlChildren[0]->xmlChildren);
49
        // Eye
50
        $this->assertInstanceOf(XmlConvertibleObject::class, $result->xmlChildren[0]->xmlChildren[0]);
51
        $this->assertNotNull(
52
            $result->xmlChildren[0]->xmlChildren[0]->xmlChildren
53
        );
54
        $this->assertCount(
55
            1,
56
            // Sub-person
57
            $result->xmlChildren[0]->xmlChildren[0]->xmlChildren
58
        );
59
        $this->assertInstanceOf(
60
            Person::class,
61
            $subPerson = $result->xmlChildren[0]->xmlChildren[0]->xmlChildren[0]
62
        );
63
        $this->assertEquals(
64
            'Adam',
65
            $subPerson->name
66
        );
67
        $this->assertEquals(
68
            'Morgan',
69
            $subPerson->surname
70
        );
71
    }
72
73
    public function testEmptyIntersect()
74
    {
75
        $first = new Person('Alex', "Lowe", [
76
            new XmlConvertibleObject('inner')
77
        ]);
78
        $second = clone $first;
79
80
        $result = $first->xmlIntersect($second);
81
        $this->assertInstanceOf(Person::class, $result);
82
        $this->assertCount(1, $result->getXmlChildren());
83
        $this->assertInstanceOf(XmlConvertibleObject::class, $result->getXmlChildren()[0]);
84
        $this->assertEquals('inner', $result->getXmlChildren()[0]->getXmlElementName());
85
    }
86
87
    public function testDifferentElements()
88
    {
89
        $xml = new Person();
90
        $compared = new Head();
91
        $this->assertNull($xml->xmlIntersect($compared));
92
    }
93
94
    public function testOne()
95
    {
96
        $first = new Person('Alex', "First");
97
        $second = clone $first;
0 ignored issues
show
Unused Code introduced by
$second is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
98
99
        $result = $first->xmlIntersect($first);
100
        $this->assertInstanceOf(get_class($first), $result);
101
    }
102
}