public function testSetMethod() { $cartId = 12; $carrierCode = 34; $methodCode = 56; $countryId = 1; $this->quoteRepositoryMock->expects($this->once())->method('get')->with($cartId)->will($this->returnValue($this->quoteMock)); $this->quoteMock->expects($this->once())->method('getItemsCount')->will($this->returnValue(1)); $this->quoteMock->expects($this->once())->method('isVirtual')->will($this->returnValue(false)); $this->quoteMock->expects($this->once())->method('getShippingAddress')->will($this->returnValue($this->shippingAddressMock)); $billingAddressMock = $this->getMock('\\Magento\\Sales\\Model\\Quote\\Address', ['getCountryId', '__wakeup'], [], '', false); $this->quoteMock->expects($this->once())->method('getBillingAddress')->will($this->returnValue($billingAddressMock)); $billingAddressMock->expects($this->once())->method('getCountryId')->will($this->returnValue(23)); $this->shippingAddressMock->expects($this->once())->method('getCountryId')->will($this->returnValue($countryId)); $this->shippingAddressMock->expects($this->once())->method('setShippingMethod')->with($carrierCode . '_' . $methodCode); $this->shippingAddressMock->expects($this->once())->method('requestShippingRates')->will($this->returnValue(true)); $this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnSelf()); $this->quoteMock->expects($this->once())->method('save'); $this->assertTrue($this->service->setMethod($cartId, $carrierCode, $methodCode)); }