/** * Test creating an address object from a SDK physical address payload. * Should fill out the builder object and then create a data object * containing the payload data. */ public function testTransferPhysicalAddressPayloadToAddress() { $payload = $this->romFactory->buildPayload('\\eBayEnterprise\\RetailOrderManagement\\Payload\\Address\\SuggestedAddress'); $payload->setLines(implode("\n", $this->street))->setCity($this->city)->setMainDivision($this->regionCode)->setCountryCode($this->countryId)->setPostalCode($this->postcode); $this->regionHelper->expects($this->any())->method('loadRegion')->will($this->returnValue($this->directoryRegion)); $this->addressData->expects($this->once())->method('setStreet')->with($this->identicalTo($this->street))->will($this->returnSelf()); $this->addressData->expects($this->once())->method('setCity')->with($this->identicalTo($this->city))->will($this->returnSelf()); $this->addressData->expects($this->once())->method('setCountryId')->with($this->identicalTo($this->countryId))->will($this->returnSelf()); $this->addressData->expects($this->once())->method('setRegionName')->with($this->identicalTo($this->regionName))->will($this->returnSelf()); $this->addressData->expects($this->once())->method('setRegionCode')->with($this->identicalTo($this->regionCode))->will($this->returnSelf()); $this->addressData->expects($this->once())->method('setRegionId')->with($this->identicalTo($this->regionId))->will($this->returnSelf()); $this->addressData->expects($this->once())->method('setPostcode')->with($this->identicalTo($this->postcode))->will($this->returnSelf()); $this->sdkHelper->transferPhysicalAddressPayloadToAddress($payload, $this->addressData); }
/** * @param SdkHelper * @param IValidationReply * @param AddressInterfaceFactory * @param AddressInterface */ public function __construct(SdkHelper $sdkHelper, IValidationReply $replyPayload, AddressInterfaceFactory $addressFactory, AddressInterface $originalAddress) { $this->id = uniqid('AVR-'); $this->originalAddress = $originalAddress; // Extract data from the payload so the payload instance doesn't need // to be stored (may not be session safe and this object may need // to go into the session). $this->isValid = $replyPayload->isValid(); $this->isAcceptable = $replyPayload->isAcceptable(); $this->resultCode = $replyPayload->getResultCode(); $this->errorLocations = []; foreach ($replyPayload->getErrorLocations() as $errorLocation) { $this->errorLocations[] = $errorLocation->getFieldName(); } $this->hasSuggestions = $replyPayload->hasSuggestions(); $this->suggestions = []; foreach ($replyPayload->getSuggestedAddresses() as $suggestedAddress) { $this->suggestions[uniqid('AVS-')] = $sdkHelper->transferPhysicalAddressPayloadToAddress($suggestedAddress, $addressFactory->create()); } $this->suggestionCount = $replyPayload->getResultSuggestionCount(); $this->correctedAddress = $sdkHelper->transferPhysicalAddressPayloadToAddress($replyPayload, $addressFactory->create()); }