/** * @param \SubscribePro\Service\Address\AddressInterface $address * @return \SubscribePro\Service\Address\AddressInterface * @throws \SubscribePro\Exception\EntityInvalidDataException * @throws \SubscribePro\Exception\HttpException */ public function findOrSave(AddressInterface $address) { if (!$address->isValid()) { throw new EntityInvalidDataException('Not all required fields are set.'); } $response = $this->httpClient->post('/services/v2/address/find-or-create.json', [self::API_NAME_ADDRESS => $address->getFormData()]); return $this->retrieveItem($response, self::API_NAME_ADDRESS, $address); }
/** * @param array $data * @dataProvider getAsChildFormDataProvider */ public function testGetAsChildFormData($data) { $expectedData = [AddressInterface::CITY => 'city', AddressInterface::COUNTRY => 'country', AddressInterface::COMPANY => 'company', AddressInterface::FIRST_NAME => 'first name', AddressInterface::LAST_NAME => 'last name', AddressInterface::MIDDLE_NAME => 'middle name', AddressInterface::PHONE => 'phone', AddressInterface::POSTCODE => 'postcode', AddressInterface::REGION => 'region', AddressInterface::STREET1 => 'street1', AddressInterface::STREET2 => 'street2']; $this->address->importData($data); $this->assertEquals($expectedData, $this->address->getFormData()); }