/** * {@inheritdoc} */ public function add(CustomerInterface $customer, AddressInterface $address) { foreach ($customer->getAddresses() as $customerAddress) { if ($this->addressComparator->equal($customerAddress, $address)) { return; } } $customer->addAddress($address); }
function it_adds_an_address_when_different_than_the_ones_present_on_the_customer(AddressComparatorInterface $addressComparator, CustomerInterface $customer, AddressInterface $customerAddress, AddressInterface $newAddress, Collection $addresses, \Iterator $iterator) { $iterator->rewind()->shouldBeCalled(); $iterator->valid()->willReturn(true); $iterator->current()->willReturn($customerAddress); $iterator->valid()->willReturn(false); $addresses->getIterator()->willReturn($iterator); $customer->getAddresses()->willReturn($addresses); $addressComparator->equal($customerAddress, $newAddress)->willReturn(false); $customer->addAddress($newAddress)->shouldBeCalled(); $this->add($customer, $newAddress); }
/** * @Given /^(this customer) has an (address "[^"]+", "[^"]+", "[^"]+", "[^"]+", "[^"]+"(?:|, "[^"]+")) in their address book$/ */ public function thisCustomerHasAnAddressInAddressBook(CustomerInterface $customer, AddressInterface $address) { $customer->addAddress($address); $this->customerManager->flush(); }
/** * @param CustomerInterface $customer * @param AddressInterface $address */ private function addAddressToCustomer(CustomerInterface $customer, AddressInterface $address) { $customer->addAddress($address); $this->customerManager->flush(); }