1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Bpost\Order\Box; |
4
|
|
|
|
5
|
|
|
use Bpost\BpostApiClient\Bpost\Order\Address; |
6
|
|
|
use Bpost\BpostApiClient\Bpost\Order\Box\BpostOnAppointment; |
7
|
|
|
use Bpost\BpostApiClient\Bpost\Order\Receiver; |
8
|
|
|
use DOMDocument; |
9
|
|
|
use DOMElement; |
10
|
|
|
use PHPUnit_Framework_TestCase; |
|
|
|
|
11
|
|
|
use SimpleXMLElement; |
12
|
|
|
|
13
|
|
|
class BpostOnAppointmentTest extends PHPUnit_Framework_TestCase |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Create a generic DOM Document |
17
|
|
|
* |
18
|
|
|
* @return DOMDocument |
19
|
|
|
*/ |
20
|
|
|
private function createDomDocument() |
21
|
|
|
{ |
22
|
|
|
$document = new DOMDocument('1.0', 'utf-8'); |
23
|
|
|
$document->preserveWhiteSpace = false; |
24
|
|
|
$document->formatOutput = true; |
25
|
|
|
|
26
|
|
|
return $document; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param DOMDocument $document |
31
|
|
|
* @param DOMElement $element |
32
|
|
|
* |
33
|
|
|
* @return DOMDocument |
34
|
|
|
*/ |
35
|
|
|
private function generateDomDocument(DOMDocument $document, DOMElement $element) |
36
|
|
|
{ |
37
|
|
|
$element->setAttribute( |
38
|
|
|
'xmlns:common', |
39
|
|
|
'http://schema.post.be/shm/deepintegration/v3/common' |
40
|
|
|
); |
41
|
|
|
$element->setAttribute( |
42
|
|
|
'xmlns:tns', |
43
|
|
|
'http://schema.post.be/shm/deepintegration/v3/' |
44
|
|
|
); |
45
|
|
|
$element->setAttribute( |
46
|
|
|
'xmlns', |
47
|
|
|
'http://schema.post.be/shm/deepintegration/v3/national' |
48
|
|
|
); |
49
|
|
|
$element->setAttribute( |
50
|
|
|
'xmlns:international', |
51
|
|
|
'http://schema.post.be/shm/deepintegration/v3/international' |
52
|
|
|
); |
53
|
|
|
$element->setAttribute( |
54
|
|
|
'xmlns:xsi', |
55
|
|
|
'http://www.w3.org/2001/XMLSchema-instance' |
56
|
|
|
); |
57
|
|
|
$element->setAttribute( |
58
|
|
|
'xsi:schemaLocation', |
59
|
|
|
'http://schema.post.be/shm/deepintegration/v3/' |
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
$document->appendChild($element); |
63
|
|
|
|
64
|
|
|
return $document; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Tests Address->toXML |
69
|
|
|
*/ |
70
|
|
|
public function testToXML() |
71
|
|
|
{ |
72
|
|
|
$address = new Address(); |
73
|
|
|
$address->setCountryCode('BE'); |
74
|
|
|
$address->setPostalCode('1040'); |
75
|
|
|
$address->setLocality('Brussels'); |
76
|
|
|
$address->setStreetName('Rue du Grand Duc'); |
77
|
|
|
$address->setNumber('13'); |
78
|
|
|
|
79
|
|
|
$receiver = new Receiver(); |
80
|
|
|
$receiver->setName('La Pomme'); |
81
|
|
|
$receiver->setEmailAddress('[email protected]'); |
82
|
|
|
$receiver->setCompany('Antidot'); |
83
|
|
|
$receiver->setAddress($address); |
84
|
|
|
$receiver->setPhoneNumber('026411390'); |
85
|
|
|
|
86
|
|
|
$self = new BpostOnAppointment(); |
87
|
|
|
$self->setProduct('bpack 24h Pro'); |
88
|
|
|
$self->setInNetworkCutOff('2016-03-16'); |
89
|
|
|
$self->setReceiver($receiver); |
90
|
|
|
|
91
|
|
|
// Normal |
92
|
|
|
$rootDom = $this->createDomDocument(); |
93
|
|
|
$document = $this->generateDomDocument($rootDom, $self->toXml($rootDom)); |
94
|
|
|
|
95
|
|
|
$this->assertEquals($this->getNormalXml(), $document->saveXML()); |
96
|
|
|
|
97
|
|
|
return; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function testCreateFromXml() |
101
|
|
|
{ |
102
|
|
|
$self = BpostOnAppointment::createFromXml(new SimpleXMLElement($this->getNormalXml())); |
103
|
|
|
|
104
|
|
|
$this->assertSame('2016-03-16', $self->getInNetworkCutOff()); |
105
|
|
|
|
106
|
|
|
$this->assertNotNull($self->getReceiver()); |
107
|
|
|
$this->assertSame('Antidot', $self->getReceiver()->getCompany()); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @expectedException \Bpost\BpostApiClient\Exception\XmlException\BpostXmlInvalidItemException |
112
|
|
|
*/ |
113
|
|
|
public function testCreateFromNotBpostOnAppointmentXml() |
114
|
|
|
{ |
115
|
|
|
BpostOnAppointment::createFromXml(new SimpleXMLElement($this->getNotBpostOnAppointmentXml())); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
private function getNormalXml() |
119
|
|
|
{ |
120
|
|
|
return <<<EOF |
121
|
|
|
<?xml version="1.0" encoding="utf-8"?> |
122
|
|
|
<nationalBox xmlns="http://schema.post.be/shm/deepintegration/v3/national" xmlns:common="http://schema.post.be/shm/deepintegration/v3/common" xmlns:tns="http://schema.post.be/shm/deepintegration/v3/" xmlns:international="http://schema.post.be/shm/deepintegration/v3/international" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schema.post.be/shm/deepintegration/v3/"> |
123
|
|
|
<bpostOnAppointment> |
124
|
|
|
<product>bpack 24h Pro</product> |
125
|
|
|
<receiver> |
126
|
|
|
<common:name>La Pomme</common:name> |
127
|
|
|
<common:company>Antidot</common:company> |
128
|
|
|
<common:address> |
129
|
|
|
<common:streetName>Rue du Grand Duc</common:streetName> |
130
|
|
|
<common:number>13</common:number> |
131
|
|
|
<common:postalCode>1040</common:postalCode> |
132
|
|
|
<common:locality>Brussels</common:locality> |
133
|
|
|
<common:countryCode>BE</common:countryCode> |
134
|
|
|
</common:address> |
135
|
|
|
<common:emailAddress>[email protected]</common:emailAddress> |
136
|
|
|
<common:phoneNumber>026411390</common:phoneNumber> |
137
|
|
|
</receiver> |
138
|
|
|
<inNetworkCutOff>2016-03-16</inNetworkCutOff> |
139
|
|
|
</bpostOnAppointment> |
140
|
|
|
</nationalBox> |
141
|
|
|
|
142
|
|
|
EOF; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
private function getNotBpostOnAppointmentXml() |
146
|
|
|
{ |
147
|
|
|
return <<<EOF |
148
|
|
|
<?xml version="1.0" encoding="utf-8"?> |
149
|
|
|
<nationalBox xmlns="http://schema.post.be/shm/deepintegration/v3/national" xmlns:common="http://schema.post.be/shm/deepintegration/v3/common" xmlns:tns="http://schema.post.be/shm/deepintegration/v3/" xmlns:international="http://schema.post.be/shm/deepintegration/v3/international" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schema.post.be/shm/deepintegration/v3/"> |
150
|
|
|
<bpostAtHome> |
151
|
|
|
<product>bpack 24h Pro</product> |
152
|
|
|
<receiver> |
153
|
|
|
<common:name>La Pomme</common:name> |
154
|
|
|
<common:company>Antidot</common:company> |
155
|
|
|
<common:address> |
156
|
|
|
<common:streetName>Rue du Grand Duc</common:streetName> |
157
|
|
|
<common:number>13</common:number> |
158
|
|
|
<common:postalCode>1040</common:postalCode> |
159
|
|
|
<common:locality>Brussels</common:locality> |
160
|
|
|
<common:countryCode>BE</common:countryCode> |
161
|
|
|
</common:address> |
162
|
|
|
<common:emailAddress>[email protected]</common:emailAddress> |
163
|
|
|
<common:phoneNumber>026411390</common:phoneNumber> |
164
|
|
|
</receiver> |
165
|
|
|
<inNetworkCutOff>2016-03-16</inNetworkCutOff> |
166
|
|
|
</bpostAtHome> |
167
|
|
|
</nationalBox> |
168
|
|
|
|
169
|
|
|
EOF; |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths