/** * Tests Address->createFromXML */ public function testCreateFromXML() { $data = array('streetName' => 'Afrikalaan', 'number' => '289', 'box' => '3', 'postalCode' => '9000', 'locality' => 'Gent', 'countryCode' => 'BE'); $document = self::createDomDocument(); $addressElement = $document->createElement('address'); foreach ($data as $key => $value) { $addressElement->appendChild($document->createElement($key, $value)); } $document->appendChild($addressElement); $address = Address::createFromXML(simplexml_load_string($document->saveXML())); $this->assertEquals($data['streetName'], $address->getStreetName()); $this->assertEquals($data['number'], $address->getNumber()); $this->assertEquals($data['box'], $address->getBox()); $this->assertEquals($data['postalCode'], $address->getPostalCode()); $this->assertEquals($data['locality'], $address->getLocality()); $this->assertEquals($data['countryCode'], $address->getCountryCode()); }
/** * @param \SimpleXMLElement $xml * @param Customer $instance * @return Customer */ public static function createFromXMLHelper(\SimpleXMLElement $xml, Customer $instance) { if (isset($xml->name) && $xml->name != '') { $instance->setName((string) $xml->name); } if (isset($xml->company) && $xml->company != '') { $instance->setCompany((string) $xml->company); } if (isset($xml->address)) { $instance->setAddress(Address::createFromXML($xml->address)); } if (isset($xml->emailAddress) && $xml->emailAddress != '') { $instance->setEmailAddress((string) $xml->emailAddress); } if (isset($xml->phoneNumber) && $xml->phoneNumber != '') { $instance->setPhoneNumber((string) $xml->phoneNumber); } return $instance; }