Passed
Branch master (8fa86f)
by Alexander
04:20
created

ReversibleTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 65
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testFromFirst() 0 17 1
B testToFirst() 0 44 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: horat1us
5
 * Date: 5/2/17
6
 * Time: 4:12 PM
7
 */
8
9
namespace Horat1us\Tests;
10
11
12
use Horat1us\Examples\Person;
13
14
class ReversibleTest extends \PHPUnit_Framework_TestCase
15
{
16
    public function testFromFirst()
17
    {
18
        $xml = '<?xml version="1.0"?>
19
<Person name="Alexander" surname="Letnikow"><Head size="big" mind="small"/></Person>
20
';
21
22
        $document = new \DOMDocument();
23
        $document->loadXML($xml);
24
25
        $person = Person::fromXml($document);
26
27
        $document = new \DOMDocument();
28
        $node = $person->toXml($document);
29
        $document->appendChild($node);
30
        $result = $document->saveXML();
31
        $this->assertEquals($xml, $result);
32
    }
33
34
    public function testToFirst()
35
    {
36
        $person = new Person();
37
38
        $person->name = 'Alexander';
39
        $person->surname = 'Letnikow';
40
41
        $childPerson = new Person();
42
        $childPerson->name = 'Some';
43
        $childPerson->surname = 'Name';
44
45
        $subChildPersonFirst = new Person();
46
        $subChildPersonFirst->name = 'Sub';
47
        $subChildPersonFirst->surname = 'First';
48
49
        $subChildPersonSecond = new Person();
50
        $subChildPersonSecond->name = 'Sub';
51
        $subChildPersonSecond->surname = 'Second';
52
53
        $childPerson->xmlChildren = [
54
            $subChildPersonFirst,
55
            $subChildPersonSecond
56
        ];
57
58
        $person->xmlChildren = [$childPerson];
59
60
        $documentGenerated = new \DOMDocument();
61
        $documentReversed = new \DOMDocument();
62
63
64
        $xml = $person->toXml($documentGenerated);
65
        $documentGenerated->appendChild($xml);
66
67
        $saved = $documentGenerated->saveXML();
68
69
        $documentParsed = new \DOMDocument();
70
        $documentParsed->loadXML($saved);
71
72
        $result = Person::fromXml($documentParsed)->toXml($documentReversed);
73
        $documentReversed->appendChild($result);
74
75
        $this->assertEquals($saved, $documentReversed->saveXML());
76
77
    }
78
}