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

AliasTest::testWrongAliasInstance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: horat1us
5
 * Date: 5/2/17
6
 * Time: 4:33 PM
7
 */
8
9
namespace Horat1us\Tests;
10
11
12
use Horat1us\Examples\Person;
13
use Horat1us\XmlConvertibleObject;
14
15
class AliasTest extends \PHPUnit_Framework_TestCase
16
{
17
    public function testWrongAliasClass()
18
    {
19
        $xml = '<?xml version="1.0"?>
20
<Person name="Alexander" surname="Letnikow"><Head size="big" mind="small"/></Person>
21
';
22
        $document = new \DOMDocument();
23
        $document->loadXML($xml);
24
25
        $this->expectException(\UnexpectedValueException::class);
26
        $this->expectExceptionCode(3);
27
        Person::fromXml($document, [
28
            'Person' => static::class,
29
            'Some' => Person::class,
30
        ]);
31
32
    }
33
34
    public function testWrongAliasType()
35
    {
36
        $xml = '<?xml version="1.0"?>
37
<Person name="Alexander" surname="Letnikow"><Head size="big" mind="small"/></Person>
38
';
39
        $document = new \DOMDocument();
40
        $document->loadXML($xml);
41
42
43
        $this->expectException(\UnexpectedValueException::class);
44
        $this->expectExceptionCode(2);
45
        Person::fromXml($document, [
46
            'Person' => 2,
47
            'Some' => Person::class
48
        ]);
49
    }
50
51
    public function testWrongAliasInstance()
52
    {
53
        $xml = '<?xml version="1.0"?>
54
<Person name="Alexander" surname="Letnikow"><Head size="big" mind="small"/></Person>
55
';
56
        $document = new \DOMDocument();
57
        $document->loadXML($xml);
58
59
60
        $this->expectException(\UnexpectedValueException::class);
61
        $this->expectExceptionCode(1);
62
        Person::fromXml($document, [
63
            'Person' => $this,
64
            'Some' => Person::class,
65
        ]);
66
    }
67
68
    public function testCustomAlias()
69
    {
70
        $xml = '<?xml version="1.0"?>
71
<Person name="Alexander" surname="Letnikow"><Head size="big" mind="small"/></Person>
72
';
73
        $document = new \DOMDocument();
74
        $document->loadXML($xml);
75
76
        $person = Person::fromXml($document, [
77
            'Person' => XmlConvertibleObject::class,
78
            'Custom' => Person::class,
79
        ]);
80
        $this->assertInstanceOf(XmlConvertibleObject::class, $person);
81
    }
82
83
    public function testCustomAliasInstance()
84
    {
85
        $xml = '<?xml version="1.0"?>
86
<Person name="Alexander" surname="Letnikow"><Head size="big" mind="small"/></Person>
87
';
88
        $document = new \DOMDocument();
89
        $document->loadXML($xml);
90
91
        $instance = new XmlConvertibleObject();
92
        $person = Person::fromXml($document, [
93
            'Person' => $instance,
94
            'Custom' => Person::class,
95
        ]);
96
        $this->assertInstanceOf(XmlConvertibleObject::class, $person);
97
        $this->assertEquals($instance, $person);
98
    }
99
}