1 | <?php |
||
16 | new XmlConvertibleObject('Eye'), |
||
17 | new XmlConvertibleObject('Eye', [ |
||
18 | new Person('Adam', 'Morgan'), |
||
19 | ]), |
||
20 | ]) |
||
21 | ]); |
||
22 | |||
23 | $compared = new Person("Alex", "Letni", [ |
||
24 | new Head('small', null, [ |
||
25 | new XmlConvertibleObject('Eye', [ |
||
26 | new Person('Adam', 'Morgan'), |
||
27 | ]), |
||
28 | ]) |
||
29 | ]); |
||
30 | |||
31 | |||
32 | $result = $xml->xmlIntersect($compared); |
||
33 | $this->assertInstanceOf(Person::class, $result); |
||
34 | /** @var Person $result */ |
||
35 | |||
36 | $this->assertEquals($result->name, $compared->name); |
||
37 | $this->assertEquals($result->name, $xml->name); |
||
38 | $this->assertNotNull($result->xmlChildren); |
||
39 | $this->assertCount(1, $result->xmlChildren); |
||
40 | $this->assertInstanceOf(Head::class, $result->xmlChildren[0]); |
||
41 | $this->assertNotNull($result->xmlChildren[0]->xmlChildren); |
||
42 | $this->assertCount(1, $result->xmlChildren[0]->xmlChildren); |
||
43 | // Eye |
||
44 | $this->assertInstanceOf(XmlConvertibleObject::class, $result->xmlChildren[0]->xmlChildren[0]); |
||
45 | $this->assertNotNull( |
||
46 | $result->xmlChildren[0]->xmlChildren[0]->xmlChildren |
||
47 | ); |
||
48 | $this->assertCount( |
||
49 | 1, |
||
50 | // Sub-person |
||
51 | $result->xmlChildren[0]->xmlChildren[0]->xmlChildren |
||
52 | ); |
||
53 | $this->assertInstanceOf( |
||
54 | Person::class, |
||
55 | $subPerson = $result->xmlChildren[0]->xmlChildren[0]->xmlChildren[0] |
||
56 | ); |
||
57 | $this->assertEquals( |
||
58 | 'Adam', |
||
59 | $subPerson->name |
||
60 | ); |
||
61 | $this->assertEquals( |
||
62 | 'Morgan', |
||
63 | $subPerson->surname |
||
64 | ); |
||
65 | } |
||
66 | |||
67 | public function testEmptyIntersect() |
||
68 | { |
||
69 | $first = new Person('Alex', "Lowe", [ |
||
70 | new XmlConvertibleObject('inner') |
||
71 | ]); |
||
72 | $second = clone $first; |
||
73 | |||
74 | $result = $first->xmlIntersect($second); |
||
75 | $this->assertInstanceOf(Person::class, $result); |
||
76 | $this->assertCount(1, $result->getXmlChildren()); |
||
77 | $this->assertInstanceOf(XmlConvertibleObject::class, $result->getXmlChildren()[0]); |
||
78 | $this->assertEquals('inner', $result->getXmlChildren()[0]->getXmlElementName()); |
||
79 | } |
||
80 | |||
81 | public function testDifferentElements() |
||
82 | { |
||
83 | $xml = new Person(); |
||
84 | $compared = new Head(); |
||
85 | $this->assertNull($xml->xmlIntersect($compared)); |
||
86 | } |
||
87 | |||
88 | public function testOne() |
||
89 | { |
||
90 | $first = new Person('Alex', "First"); |
||
91 | $second = clone $first; |
||
92 | |||
93 | $result = $first->xmlIntersect($first); |
||
94 | $this->assertInstanceOf(get_class($first), $result); |
||
95 | } |
||
96 | } |
||
97 |