Ejemplo n.º 1
0
 /**
  * Tests the method when the address being saved is already persisted.
  */
 public function testSavingAlreadyPersistedAddress()
 {
     $originalAddress = $this->getAddress('42', 'New address');
     $clonedAddress = $this->getAddress(null, 'New address');
     $this->addressObjectManagerMock->expects($this->once())->method('persist')->with($clonedAddress);
     $this->addressObjectManagerMock->expects($this->once())->method('flush')->with($clonedAddress);
     $this->addressEventDispatcher->expects($this->once())->method('dispatchAddressOnCloneEvent');
     $savedAddress = $this->addressManager->saveAddress($originalAddress);
     $this->assertEquals($savedAddress, $clonedAddress, 'The saved address should be a new one');
 }
Ejemplo n.º 2
0
 /**
  * Saves an address making a copy in case it was already persisted. Then
  * returns the saved address.
  *
  * @param AddressInterface $address The address to save
  *
  * @return AddressInterface saved address.
  */
 public function saveAddress(AddressInterface $address)
 {
     if ($address->getId()) {
         $addressToSave = clone $address;
         $addressToSave->setId(null);
         $this->addressObjectManager->refresh($address);
         $this->addressObjectManager->persist($addressToSave);
         $this->addressObjectManager->flush($addressToSave);
         $this->addressEventDispatcher->dispatchAddressOnCloneEvent($address, $addressToSave);
         return $addressToSave;
     }
     $this->addressObjectManager->flush($address);
     return $address;
 }