/** * Test validation in the setters */ public function testFaultyProperties() { $address = new PugoAddress(); try { $address->setBox(str_repeat('a', 9)); } catch (\Exception $e) { $this->assertInstanceOf('TijsVerkoyen\\Bpost\\Exception', $e); $this->assertEquals('Invalid length, maximum is 8.', $e->getMessage()); } try { $address->setCountryCode(str_repeat('a', 3)); } catch (\Exception $e) { $this->assertInstanceOf('TijsVerkoyen\\Bpost\\Exception', $e); $this->assertEquals('Invalid length, maximum is 2.', $e->getMessage()); } try { $address->setLocality(str_repeat('a', 41)); } catch (\Exception $e) { $this->assertInstanceOf('TijsVerkoyen\\Bpost\\Exception', $e); $this->assertEquals('Invalid length, maximum is 40.', $e->getMessage()); } try { $address->setNumber(str_repeat('a', 9)); } catch (\Exception $e) { $this->assertInstanceOf('TijsVerkoyen\\Bpost\\Exception', $e); $this->assertEquals('Invalid length, maximum is 8.', $e->getMessage()); } try { $address->setPostalCode(str_repeat('a', 41)); } catch (\Exception $e) { $this->assertInstanceOf('TijsVerkoyen\\Bpost\\Exception', $e); $this->assertEquals('Invalid length, maximum is 40.', $e->getMessage()); } try { $address->setStreetName(str_repeat('a', 41)); } catch (\Exception $e) { $this->assertInstanceOf('TijsVerkoyen\\Bpost\\Exception', $e); $this->assertEquals('Invalid length, maximum is 40.', $e->getMessage()); } }
/** * @param \SimpleXMLElement $xml * @return AtBpost */ public static function createFromXML(\SimpleXMLElement $xml) { $atBpost = new AtBpost(); if (isset($xml->atBpost->product) && $xml->atBpost->product != '') { $atBpost->setProduct((string) $xml->atBpost->product); } if (isset($xml->atBpost->options)) { foreach ($xml->atBpost->options as $optionData) { $optionData = $optionData->children('http://schema.post.be/shm/deepintegration/v3/common'); if (in_array($optionData->getName(), array('infoDistributed', 'infoNextDay', 'infoReminder', 'keepMeInformed'))) { $option = Messaging::createFromXML($optionData); } else { $className = '\\TijsVerkoyen\\Bpost\\Bpost\\Order\\Box\\Option\\' . ucfirst($optionData->getName()); if (!method_exists($className, 'createFromXML')) { throw new Exception('Not Implemented'); } $option = call_user_func(array($className, 'createFromXML'), $optionData); } $atBpost->addOption($option); } } if (isset($xml->atBpost->weight) && $xml->atBpost->weight != '') { $atBpost->setWeight((int) $xml->atBpost->weight); } if (isset($xml->atBpost->receiverName) && $xml->atBpost->receiverName != '') { $atBpost->setReceiverName((string) $xml->atBpost->receiverName); } if (isset($xml->atBpost->receiverCompany) && $xml->atBpost->receiverCompany != '') { $atBpost->setReceiverCompany((string) $xml->atBpost->receiverCompany); } if (isset($xml->atBpost->pugoId) && $xml->atBpost->pugoId != '') { $atBpost->setPugoId((string) $xml->atBpost->pugoId); } if (isset($xml->atBpost->pugoName) && $xml->atBpost->pugoName != '') { $atBpost->setPugoName((string) $xml->atBpost->pugoName); } if (isset($xml->atBpost->pugoAddress)) { $pugoAddressData = $xml->atBpost->pugoAddress->children('http://schema.post.be/shm/deepintegration/v3/common'); $atBpost->setPugoAddress(PugoAddress::createFromXML($pugoAddressData)); } return $atBpost; }