56 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
57 $this->shippingMethodDataFactoryMock = $this->createPartialMock(
58 \
Magento\
Quote\Api\Data\ShippingMethodInterfaceFactory::class,
61 $this->storeManagerMock = $this->createMock(\
Magento\
Store\Model\StoreManagerInterface::class);
62 $this->currencyMock = $this->createMock(\
Magento\Directory\Model\Currency::class);
63 $this->shippingMethodMock = $this->createPartialMock(
78 $this->rateModelMock = $this->createPartialMock(
90 $this->storeMock = $this->createMock(\
Magento\
Store\Model\Store::class);
91 $this->taxHelper = $this->createMock(\
Magento\Tax\Helper\Data::class);
94 \
Magento\
Quote\Model\Cart\ShippingMethodConverter::class,
96 'shippingMethodDataFactory' => $this->shippingMethodDataFactoryMock,
97 'storeManager' => $this->storeManagerMock,
98 'taxHelper' => $this->taxHelper
105 $customerTaxClassId = 100;
106 $shippingPriceExclTax = 1000;
107 $shippingPriceInclTax = 1500;
110 $this->storeManagerMock->expects($this->once())->method(
'getStore')->will($this->returnValue($this->storeMock));
111 $this->storeMock->expects($this->once())
112 ->method(
'getBaseCurrency')
113 ->will($this->returnValue($this->currencyMock));
115 $this->rateModelMock->expects($this->once())->method(
'getCarrier')->will($this->returnValue(
'CARRIER_CODE'));
116 $this->rateModelMock->expects($this->once())->method(
'getMethod')->will($this->returnValue(
'METHOD_CODE'));
117 $this->rateModelMock->expects($this->any())->method(
'getPrice')->will($this->returnValue(
$price));
118 $this->currencyMock->expects($this->at(0))
119 ->method(
'convert')->with(
$price,
'USD')->willReturn(100.12);
120 $this->currencyMock->expects($this->at(1))
121 ->method(
'convert')->with($shippingPriceExclTax,
'USD')->willReturn($shippingPriceExclTax);
122 $this->currencyMock->expects($this->at(2))
123 ->method(
'convert')->with($shippingPriceInclTax,
'USD')->willReturn($shippingPriceInclTax);
125 $this->rateModelMock->expects($this->once())
126 ->method(
'getCarrierTitle')->will($this->returnValue(
'CARRIER_TITLE'));
127 $this->rateModelMock->expects($this->once())
128 ->method(
'getMethodTitle')->will($this->returnValue(
'METHOD_TITLE'));
130 $quoteMock = $this->createMock(\
Magento\
Quote\Model\Quote::class);
132 $this->rateModelMock->expects($this->exactly(4))->method(
'getAddress')->willReturn($addressMock);
134 $addressMock->expects($this->exactly(2))->method(
'getQuote')->willReturn($quoteMock);
135 $quoteMock->expects($this->exactly(2))->method(
'getCustomerTaxClassId')->willReturn($customerTaxClassId);
137 $this->shippingMethodDataFactoryMock->expects($this->once())
139 ->will($this->returnValue($this->shippingMethodMock));
141 $this->shippingMethodMock->expects($this->once())
142 ->method(
'setCarrierCode')
143 ->with(
'CARRIER_CODE')
144 ->will($this->returnValue($this->shippingMethodMock));
145 $this->shippingMethodMock->expects($this->once())
146 ->method(
'setMethodCode')
147 ->with(
'METHOD_CODE')
148 ->will($this->returnValue($this->shippingMethodMock));
149 $this->shippingMethodMock->expects($this->once())
150 ->method(
'setCarrierTitle')
151 ->with(
'CARRIER_TITLE')
152 ->will($this->returnValue($this->shippingMethodMock));
153 $this->shippingMethodMock->expects($this->once())
154 ->method(
'setMethodTitle')
155 ->with(
'METHOD_TITLE')
156 ->will($this->returnValue($this->shippingMethodMock));
157 $this->shippingMethodMock->expects($this->once())
158 ->method(
'setAmount')
160 ->will($this->returnValue($this->shippingMethodMock));
161 $this->shippingMethodMock->expects($this->once())
162 ->method(
'setBaseAmount')
164 ->will($this->returnValue($this->shippingMethodMock));
165 $this->shippingMethodMock->expects($this->once())
166 ->method(
'setAvailable')
168 ->will($this->returnValue($this->shippingMethodMock));
169 $this->shippingMethodMock->expects($this->once())
170 ->method(
'setPriceExclTax')
171 ->with($shippingPriceExclTax)
172 ->will($this->returnValue($this->shippingMethodMock));
173 $this->shippingMethodMock->expects($this->once())
174 ->method(
'setPriceInclTax')
175 ->with($shippingPriceInclTax)
176 ->will($this->returnValue($this->shippingMethodMock));
178 $this->taxHelper->expects($this->at(0))
179 ->method(
'getShippingPrice')
180 ->with(
$price,
false, $addressMock, $customerTaxClassId)
181 ->willReturn($shippingPriceExclTax);
183 $this->taxHelper->expects($this->at(1))
184 ->method(
'getShippingPrice')
185 ->with(
$price,
true, $addressMock, $customerTaxClassId)
186 ->willReturn($shippingPriceInclTax);
189 $this->shippingMethodMock,
190 $this->converter->modelToDataObject($this->rateModelMock,
'USD')
$shippingMethodDataFactoryMock