示例#1
0
 /**
  * Test validation in the setters
  */
 public function testFaultyProperties()
 {
     try {
         new Messaging(str_repeat('a', 10), 'NL');
     } catch (\Exception $e) {
         $this->assertInstanceOf('TijsVerkoyen\\Bpost\\Exception', $e);
         $this->assertEquals(sprintf('Invalid value, possible values are: %1$s.', implode(', ', Messaging::getPossibleTypeValues())), $e->getMessage());
     }
     try {
         new Messaging('infoDistributed', str_repeat('a', 10));
     } catch (\Exception $e) {
         $this->assertInstanceOf('TijsVerkoyen\\Bpost\\Exception', $e);
         $this->assertEquals(sprintf('Invalid value, possible values are: %1$s.', implode(', ', Messaging::getPossibleLanguageValues())), $e->getMessage());
     }
     try {
         new Messaging('infoDistributed', 'NL', str_repeat('a', 51));
     } catch (\Exception $e) {
         $this->assertInstanceOf('TijsVerkoyen\\Bpost\\Exception', $e);
         $this->assertEquals('Invalid length, maximum is 50.', $e->getMessage());
     }
     try {
         new Messaging('infoDistributed', 'NL', null, str_repeat('a', 21));
     } catch (\Exception $e) {
         $this->assertInstanceOf('TijsVerkoyen\\Bpost\\Exception', $e);
         $this->assertEquals('Invalid length, maximum is 20.', $e->getMessage());
     }
 }
示例#2
0
 /**
  * @param  \SimpleXMLElement $xml
  * @return AtHome
  */
 public static function createFromXML(\SimpleXMLElement $xml)
 {
     $atHome = new AtHome();
     if (isset($xml->atHome->product) && $xml->atHome->product != '') {
         $atHome->setProduct((string) $xml->atHome->product);
     }
     if (isset($xml->atHome->options) and !empty($xml->atHome->options)) {
         foreach ($xml->atHome->options as $optionData) {
             $optionData = $optionData->children('http://schema.post.be/shm/deepintegration/v3/common');
             if (in_array($optionData->getName(), array('infoDistributed'))) {
                 $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);
             }
             $atHome->addOption($option);
         }
     }
     if (isset($xml->atHome->weight) && $xml->atHome->weight != '') {
         $atHome->setWeight((int) $xml->atHome->weight);
     }
     if (isset($xml->atHome->openingHours) && $xml->atHome->openingHours != '') {
         throw new Exception('Not Implemented');
         $atHome->setProduct((string) $xml->atHome->openingHours);
     }
     if (isset($xml->atHome->desiredDeliveryPlace) && $xml->atHome->desiredDeliveryPlace != '') {
         $atHome->setDesiredDeliveryPlace((string) $xml->atHome->desiredDeliveryPlace);
     }
     if (isset($xml->atHome->receiver)) {
         $atHome->setReceiver(Receiver::createFromXML($xml->atHome->receiver->children('http://schema.post.be/shm/deepintegration/v3/common')));
     }
     return $atHome;
 }
示例#3
0
 /**
  * @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;
 }
示例#4
0
 /**
  * @param  \SimpleXMLElement $xml
  * @return Messaging
  */
 public static function createFromXML(\SimpleXMLElement $xml)
 {
     $messaging = new Messaging($xml->getName(), (string) $xml->attributes()->language);
     $data = $xml->{$xml->getName()};
     if (isset($data->emailAddress) && $data->emailAddress != '') {
         $messaging->setEmailAddress((string) $data->emailAddress);
     }
     if (isset($data->mobilePhone) && $data->mobilePhone != '') {
         $messaging->setMobilePhone((string) $data->mobilePhone);
     }
     return $messaging;
 }