public function testExecuteWithException() { $addressId = 1; $customerId = 2; $this->resultRedirectFactory->expects($this->once())->method('create')->willReturn($this->resultRedirect); $this->request->expects($this->once())->method('getParam')->with('id', false)->willReturn($addressId); $this->validatorMock->expects($this->once())->method('validate')->with($this->request)->willReturn(true); $this->addressRepositoryMock->expects($this->once())->method('getById')->with($addressId)->willReturn($this->address); $this->sessionMock->expects($this->once())->method('getCustomerId')->willReturn($customerId); $this->address->expects($this->once())->method('getCustomerId')->willReturn(34); $exception = new \Exception('Exception'); $this->messageManager->expects($this->once())->method('addError')->with(__('We can\'t delete the address right now.'))->willThrowException($exception); $this->messageManager->expects($this->once())->method('addException')->with($exception, __('We can\'t delete the address right now.')); $this->resultRedirect->expects($this->once())->method('setPath')->with('*/*/index')->willReturnSelf(); $this->assertSame($this->resultRedirect, $this->model->execute()); }
protected function prepareMocksForUpdateDefaultBilling() { $this->prepareMocksForProcessAddressData(); $addressData = ['postcode' => '07294', 'firstname' => 'Firstname', 'lastname' => 'Lastname']; $this->customerData->expects($this->once())->method('getAddresses')->willReturn([$this->address]); $this->address->expects($this->once())->method('isDefaultBilling')->willReturn(true); $this->dataObjectHelper->expects($this->at(0))->method('populateWithArray')->with($this->address, $addressData, '\\Magento\\Customer\\Api\\Data\\AddressInterface'); }