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); }
public function testSave() { $customerId = 34; $addressId = 53; $customerAddress = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\AddressInterface', [], '', false); $addressCollection = $this->getMock('Magento\\Customer\\Model\\ResourceModel\\Address\\Collection', [], [], '', false); $customerAddress->expects($this->atLeastOnce())->method('getCustomerId')->willReturn($customerId); $customerAddress->expects($this->atLeastOnce())->method('getId')->willReturn($addressId); $this->customerRegistry->expects($this->once())->method('retrieve')->with($customerId)->willReturn($this->customer); $this->addressRegistry->expects($this->once())->method('retrieve')->with($addressId)->willReturn(null); $this->addressFactory->expects($this->once())->method('create')->willReturn($this->address); $this->address->expects($this->once())->method('updateData')->with($customerAddress); $this->address->expects($this->once())->method('setCustomer')->with($this->customer); $this->address->expects($this->once())->method('save'); $this->customerRegistry->expects($this->once())->method('remove')->with($customerId); $this->addressRegistry->expects($this->once())->method('push')->with($this->address); $this->customer->expects($this->once())->method('getAddressesCollection')->willReturn($addressCollection); $addressCollection->expects($this->once())->method('clear'); $this->address->expects($this->once())->method('getDataModel')->willReturn($customerAddress); $this->address->expects($this->once())->method('getShouldIgnoreValidation')->willReturn(true); $this->repository->save($customerAddress); }