/** * @magentoDataFixture Magento/Customer/_files/customer.php * @magentoDataFixture Magento/Customer/_files/customer_address.php * @expectedException \Magento\Framework\Exception\NoSuchEntityException */ public function testRemove() { $addressId = 1; $address = $this->_model->retrieve($addressId); $this->assertInstanceOf('\\Magento\\Customer\\Model\\Address', $address); $address->delete(); $this->_model->remove($addressId); $this->_model->retrieve($addressId); }
public function testRemove() { $addressId = 1; $address = $this->getMockBuilder('\\Magento\\Customer\\Model\\Address')->disableOriginalConstructor()->setMethods(['load', 'getId', '__wakeup'])->getMock(); $address->expects($this->exactly(2))->method('load')->with($addressId)->will($this->returnValue($address)); $address->expects($this->exactly(2))->method('getId')->will($this->returnValue($addressId)); $this->addressFactory->expects($this->exactly(2))->method('create')->will($this->returnValue($address)); $actual = $this->unit->retrieve($addressId); $this->assertEquals($address, $actual); $this->unit->remove($addressId); $actual = $this->unit->retrieve($addressId); $this->assertEquals($address, $actual); }
/** * {@inheritdoc} */ public function deleteAddress($addressId) { $address = $this->addressRegistry->retrieve($addressId); $address->delete(); $this->addressRegistry->remove($addressId); return true; }
/** * Delete customer address by ID. * * @param int $addressId * @return bool true on success * @throws \Magento\Framework\Exception\NoSuchEntityException * @throws \Magento\Framework\Exception\LocalizedException */ public function deleteById($addressId) { $address = $this->addressRegistry->retrieve($addressId); $customerModel = $this->customerRegistry->retrieve($address->getCustomerId()); $customerModel->getAddressesCollection()->clear(); $this->addressResource->delete($address); $this->addressRegistry->remove($addressId); return true; }