|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: horat1us |
|
5
|
|
|
* Date: 5/2/17 |
|
6
|
|
|
* Time: 4:41 PM |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Horat1us\Tests; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
use Horat1us\Examples\Person; |
|
13
|
|
|
use Horat1us\XmlConvertibleObject; |
|
14
|
|
|
|
|
15
|
|
|
class AttributesTest extends \PHPUnit_Framework_TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
public function testWrongAttribute() |
|
18
|
|
|
{ |
|
19
|
|
|
$xml = '<?xml version="1.0"?> |
|
20
|
|
|
<Person name="Alexander" surname="Letnikow" middlename="Alexandrovich"><Head size="big" mind="small"/></Person> |
|
21
|
|
|
'; |
|
22
|
|
|
|
|
23
|
|
|
$document = new \DOMDocument(); |
|
24
|
|
|
$document->loadXML($xml); |
|
25
|
|
|
|
|
26
|
|
|
$this->expectException(\UnexpectedValueException::class); |
|
27
|
|
|
$this->expectExceptionCode(4); |
|
28
|
|
|
|
|
29
|
|
|
Person::fromXml($document); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testAttributes() |
|
33
|
|
|
{ |
|
34
|
|
|
$name = 'Alexander'; |
|
35
|
|
|
$surname = 'Letnikow'; |
|
36
|
|
|
$xml = '<?xml version="1.0"?> |
|
37
|
|
|
<Person name="' . $name . '" surname="' . $surname . '" ><Head size="big" mind="small"/></Person> |
|
38
|
|
|
'; |
|
39
|
|
|
|
|
40
|
|
|
$document = new \DOMDocument(); |
|
41
|
|
|
$document->loadXML($xml); |
|
42
|
|
|
|
|
43
|
|
|
$person = Person::fromXml($document); |
|
44
|
|
|
$this->assertEquals($name, $person->name); |
|
45
|
|
|
$this->assertEquals($surname, $person->surname); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function testWithDefaultObject() |
|
49
|
|
|
{ |
|
50
|
|
|
$name = 'Alexander'; |
|
51
|
|
|
$surname = 'Letnikow'; |
|
52
|
|
|
$xml = '<?xml version="1.0"?> |
|
53
|
|
|
<Person name="' . $name . '" surname="' . $surname . '" ><Head size="big" mind="small"/></Person> |
|
54
|
|
|
'; |
|
55
|
|
|
|
|
56
|
|
|
$document = new \DOMDocument(); |
|
57
|
|
|
$document->loadXML($xml); |
|
58
|
|
|
|
|
59
|
|
|
$person = XmlConvertibleObject::fromXml($document); |
|
60
|
|
|
$this->assertEquals($name, $person->name); |
|
|
|
|
|
|
61
|
|
|
$this->assertEquals($surname, $person->surname); |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
} |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.