1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Horat1us\Tests; |
4
|
|
|
|
5
|
|
|
use Horat1us\Examples\Person; |
6
|
|
|
use Horat1us\XmlConvertibleObject; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
|
9
|
|
|
class AttributesTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
public function testWrongAttribute() |
12
|
|
|
{ |
13
|
|
|
$xml = '<?xml version="1.0"?> |
14
|
|
|
<Person name="Alexander" surname="Letnikow" middlename="Alexandrovich"><Head size="big" mind="small"/></Person> |
15
|
|
|
'; |
16
|
|
|
|
17
|
|
|
$document = new \DOMDocument(); |
18
|
|
|
$document->loadXML($xml); |
19
|
|
|
|
20
|
|
|
$this->expectException(\UnexpectedValueException::class); |
21
|
|
|
$this->expectExceptionCode(4); |
22
|
|
|
|
23
|
|
|
$person = Person::fromXml($document); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testAttributes() |
27
|
|
|
{ |
28
|
|
|
$name = 'Alexander'; |
29
|
|
|
$surname = 'Letnikow'; |
30
|
|
|
$xml = '<?xml version="1.0"?> |
31
|
|
|
<Person name="' . $name . '" surname="' . $surname . '" ><Head size="big" mind="small"/></Person> |
32
|
|
|
'; |
33
|
|
|
|
34
|
|
|
$document = new \DOMDocument(); |
35
|
|
|
$document->loadXML($xml); |
36
|
|
|
|
37
|
|
|
$person = Person::fromXml($document); |
38
|
|
|
$this->assertEquals($name, $person->name); |
39
|
|
|
$this->assertEquals($surname, $person->surname); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testWithDefaultObject() |
43
|
|
|
{ |
44
|
|
|
$name = 'Alexander'; |
45
|
|
|
$surname = 'Letnikow'; |
46
|
|
|
$xml = '<?xml version="1.0"?> |
47
|
|
|
<Person name="' . $name . '" surname="' . $surname . '" ><Head size="big" mind="small"/></Person> |
48
|
|
|
'; |
49
|
|
|
|
50
|
|
|
$document = new \DOMDocument(); |
51
|
|
|
$document->loadXML($xml); |
52
|
|
|
|
53
|
|
|
$person = XmlConvertibleObject::fromXml($document); |
54
|
|
|
$this->assertEquals($name, $person->{'name'}); |
55
|
|
|
$this->assertEquals($surname, $person->{'surname'}); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|