|
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", 'cool', [ |
|
22
|
|
|
new XmlConvertibleObject('Eye'), |
|
23
|
|
|
new XmlConvertibleObject('Eye', [ |
|
24
|
|
|
new Person('Adam', 'Morgan'), |
|
25
|
|
|
]), |
|
26
|
|
|
]) |
|
27
|
|
|
]); |
|
28
|
|
|
|
|
29
|
|
|
$compared = new Person("Alex", "Defined", [ |
|
30
|
|
|
new Head('small', null, [ |
|
31
|
|
|
new XmlConvertibleObject('Eye', [ |
|
32
|
|
|
new Person('Adam', 'Morgan'), |
|
33
|
|
|
]), |
|
34
|
|
|
]) |
|
35
|
|
|
]); |
|
36
|
|
|
|
|
37
|
|
|
$result = new Person(); |
|
38
|
|
|
|
|
39
|
|
|
$xml->xmlIntersect($compared, $result); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertEquals($result->name, $compared->name); |
|
42
|
|
|
$this->assertEquals($result->name, $xml->name); |
|
43
|
|
|
$this->assertNull($result->surname); |
|
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 testDifferentElements() |
|
74
|
|
|
{ |
|
75
|
|
|
$xml = new Person(); |
|
76
|
|
|
$compared = new Head(); |
|
77
|
|
|
$this->assertNull($xml->xmlIntersect($compared)); |
|
78
|
|
|
} |
|
79
|
|
|
} |