zangra-dev /
bpost-api-library
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Tests\Bpost\Order; |
||
| 4 | |||
| 5 | use Bpost\BpostApiClient\Bpost\Order\Address; |
||
| 6 | use DOMDocument; |
||
| 7 | use PHPUnit_Framework_TestCase; |
||
|
0 ignored issues
–
show
|
|||
| 8 | |||
| 9 | class AddressTest extends PHPUnit_Framework_TestCase |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * Create a generic DOM Document |
||
| 13 | * |
||
| 14 | * @return DOMDocument |
||
| 15 | */ |
||
| 16 | private static function createDomDocument() |
||
| 17 | { |
||
| 18 | $document = new DOMDocument('1.0', 'utf-8'); |
||
| 19 | $document->preserveWhiteSpace = false; |
||
| 20 | $document->formatOutput = true; |
||
| 21 | |||
| 22 | return $document; |
||
| 23 | } |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Tests Address->toXML |
||
| 27 | */ |
||
| 28 | public function testToXML() |
||
| 29 | { |
||
| 30 | $data = array( |
||
| 31 | 'streetName' => 'Afrikalaan', |
||
| 32 | 'number' => '2890', |
||
| 33 | 'box' => '3', |
||
| 34 | 'postalCode' => '9000', |
||
| 35 | 'locality' => 'Gent', |
||
| 36 | 'countryCode' => 'BE', |
||
| 37 | ); |
||
| 38 | |||
| 39 | $expectedDocument = self::createDomDocument(); |
||
| 40 | $address = $expectedDocument->createElement('common:address'); |
||
| 41 | foreach ($data as $key => $value) { |
||
| 42 | $address->appendChild( |
||
| 43 | $expectedDocument->createElement($key, $value) |
||
| 44 | ); |
||
| 45 | } |
||
| 46 | $expectedDocument->appendChild($address); |
||
| 47 | |||
| 48 | $actualDocument = self::createDomDocument(); |
||
| 49 | $address = new Address( |
||
| 50 | $data['streetName'], |
||
| 51 | $data['number'], |
||
| 52 | $data['box'], |
||
| 53 | $data['postalCode'], |
||
| 54 | $data['locality'], |
||
| 55 | $data['countryCode'] |
||
| 56 | ); |
||
| 57 | $actualDocument->appendChild( |
||
| 58 | $address->toXML($actualDocument, null) |
||
| 59 | ); |
||
| 60 | |||
| 61 | $this->assertSame($expectedDocument->saveXML(), $actualDocument->saveXML()); |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @expectedException \Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidLengthException |
||
| 66 | */ |
||
| 67 | public function testFaultyBoxProperties() |
||
| 68 | { |
||
| 69 | $address = new Address(); |
||
| 70 | $address->setBox(str_repeat('a', 9)); |
||
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @expectedException \Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidLengthException |
||
| 75 | */ |
||
| 76 | public function testFaultyCountryCodeProperties() |
||
| 77 | { |
||
| 78 | $address = new Address(); |
||
| 79 | $address->setCountryCode(str_repeat('a', 3)); |
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @expectedException \Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidLengthException |
||
| 84 | */ |
||
| 85 | public function testFaultyLocalityProperties() |
||
| 86 | { |
||
| 87 | $address = new Address(); |
||
| 88 | $address->setLocality(str_repeat('a', 41)); |
||
| 89 | } |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @expectedException \Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidLengthException |
||
| 93 | */ |
||
| 94 | public function testFaultyNumberProperties() |
||
| 95 | { |
||
| 96 | $address = new Address(); |
||
| 97 | $address->setNumber(str_repeat('a', 9)); |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @expectedException \Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidLengthException |
||
| 102 | */ |
||
| 103 | public function testFaultyPostalCodeProperties() |
||
| 104 | { |
||
| 105 | $address = new Address(); |
||
| 106 | $address->setPostalCode(str_repeat('a', 41)); |
||
| 107 | } |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @expectedException \Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidLengthException |
||
| 111 | */ |
||
| 112 | public function testFaultyStreetNameProperties() |
||
| 113 | { |
||
| 114 | $address = new Address(); |
||
| 115 | $address->setStreetName(str_repeat('a', 41)); |
||
| 116 | } |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Tests Address->createFromXML |
||
| 120 | */ |
||
| 121 | public function testCreateFromXML() |
||
| 122 | { |
||
| 123 | $data = array( |
||
| 124 | 'streetName' => 'Afrikalaan', |
||
| 125 | 'number' => '289', |
||
| 126 | 'box' => '3', |
||
| 127 | 'postalCode' => '9000', |
||
| 128 | 'locality' => 'Gent', |
||
| 129 | 'countryCode' => 'BE', |
||
| 130 | ); |
||
| 131 | |||
| 132 | $document = self::createDomDocument(); |
||
| 133 | $addressElement = $document->createElement('address'); |
||
| 134 | foreach ($data as $key => $value) { |
||
| 135 | $addressElement->appendChild( |
||
| 136 | $document->createElement($key, $value) |
||
| 137 | ); |
||
| 138 | } |
||
| 139 | $document->appendChild($addressElement); |
||
| 140 | |||
| 141 | $address = Address::createFromXML( |
||
| 142 | simplexml_load_string( |
||
| 143 | $document->saveXML() |
||
| 144 | ) |
||
| 145 | ); |
||
| 146 | |||
| 147 | $this->assertSame($data['streetName'], $address->getStreetName()); |
||
| 148 | $this->assertSame($data['number'], $address->getNumber()); |
||
| 149 | $this->assertSame($data['box'], $address->getBox()); |
||
| 150 | $this->assertSame($data['postalCode'], $address->getPostalCode()); |
||
| 151 | $this->assertSame($data['locality'], $address->getLocality()); |
||
| 152 | $this->assertSame($data['countryCode'], $address->getCountryCode()); |
||
| 153 | } |
||
| 154 | } |
||
| 155 |
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