/**
  * Test validation in the setters
  */
 public function testFaultyProperties()
 {
     $address = new ParcelsDepotAddress();
     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());
     }
 }
示例#2
0
文件: At247.php 项目: BenCavens/bpost
 /**
  * @param  \SimpleXMLElement $xml
  * @return At247
  */
 public static function createFromXML(\SimpleXMLElement $xml)
 {
     $at247 = new At247();
     if (isset($xml->{'at24-7'}->product) && $xml->{'at24-7'}->product != '') {
         $at247->setProduct((string) $xml->{'at24-7'}->product);
     }
     if (isset($xml->{'at24-7'}->options)) {
         foreach ($xml->{'at24-7'}->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);
             }
             $at247->addOption($option);
         }
     }
     if (isset($xml->{'at24-7'}->weight) && $xml->{'at24-7'}->weight != '') {
         $at247->setWeight((int) $xml->{'at24-7'}->weight);
     }
     if (isset($xml->{'at24-7'}->memberId) && $xml->{'at24-7'}->memberId != '') {
         $at247->setMemberId((string) $xml->{'at24-7'}->memberId);
     }
     if (isset($xml->{'at24-7'}->receiverName) && $xml->{'at24-7'}->receiverName != '') {
         $at247->setReceiverName((string) $xml->{'at24-7'}->receiverName);
     }
     if (isset($xml->{'at24-7'}->receiverCompany) && $xml->{'at24-7'}->receiverCompany != '') {
         $at247->setReceiverCompany((string) $xml->{'at24-7'}->receiverCompany);
     }
     if (isset($xml->{'at24-7'}->parcelsDepotId) && $xml->{'at24-7'}->parcelsDepotId != '') {
         $at247->setParcelsDepotId((string) $xml->{'at24-7'}->parcelsDepotId);
     }
     if (isset($xml->{'at24-7'}->parcelsDepotName) && $xml->{'at24-7'}->parcelsDepotName != '') {
         $at247->setParcelsDepotName((string) $xml->{'at24-7'}->parcelsDepotName);
     }
     if (isset($xml->{'at24-7'}->parcelsDepotAddress)) {
         $parcelsDepotAddressData = $xml->{'at24-7'}->parcelsDepotAddress->children('http://schema.post.be/shm/deepintegration/v3/common');
         $at247->setParcelsDepotAddress(ParcelsDepotAddress::createFromXML($parcelsDepotAddressData));
     }
     return $at247;
 }
示例#3
0
文件: index.php 项目: BenCavens/bpost
$atHome->setWeight(2000);
$atHome->setReceiver($receiver);
$atHome->addOption($option);
$box->setNationalBox($atHome);
// @Bpost
$pugoAddress = new PugoAddress('Turnhoutsebaan', '468', null, '2110', 'Wijnegem', 'BE');
$atBpost = new AtBpost();
$atBpost->setWeight(2000);
$atBpost->setPugoId('207500');
$atBpost->setPugoName('WIJNEGEM');
$atBpost->setPugoAddress($pugoAddress);
$atBpost->setReceiverName('Tijs Verkoyen');
$atBpost->setReceiverCompany('Sumo Coders');
//$box->setNationalBox($atBpost);
// @24/7
$parcelsDepotAddress = new ParcelsDepotAddress('Turnhoutsebaan', '468', null, '2110', 'Wijnegem', 'BE');
$parcelsDepotAddress->setBox('A');
$at247 = new At247();
$at247->setParcelsDepotId('014472');
$at247->setParcelsDepotName('WIJNEGEM');
$at247->setParcelsDepotAddress($parcelsDepotAddress);
$at247->setMemberId('188565346');
$at247->setReceiverName('Tijs Verkoyen');
$at247->setReceiverCompany('Sumo Coders');
//$box->setNationalBox($at247);
// international
$customsInfo = new CustomsInfo();
$customsInfo->setParcelValue(700);
$customsInfo->setContentDescription('BOOK');
$customsInfo->setShipmentType('DOCUMENTS');
$customsInfo->setParcelReturnInstructions('RTS');