Skip to content

Commit 2a9fc9a

Browse files
author
Oleksandr Gorkun
committed
MAGETWO-99673: Implement deferred
1 parent eb89c0f commit 2a9fc9a

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

app/code/Magento/Shipping/Model/Shipping.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Quote\Model\Quote\Address\RateCollectorInterface;
1010
use Magento\Quote\Model\Quote\Address\RateRequest;
1111
use Magento\Quote\Model\Quote\Address\RateRequestFactory;
12+
use Magento\Quote\Model\Quote\Address\RateResult\Error;
1213
use Magento\Sales\Model\Order\Shipment;
1314
use Magento\Shipping\Model\Carrier\AbstractCarrier;
1415
use Magento\Shipping\Model\Rate\CarrierResult;
@@ -278,7 +279,7 @@ private function prepareCarrier(string $carrierCode, RateRequest $request): Abst
278279
}
279280
$carrier->setActiveFlag($this->_availabilityConfigField);
280281
$result = $carrier->checkAvailableShipCountries($request);
281-
if (false !== $result && !$result instanceof \Magento\Quote\Model\Quote\Address\RateResult\Error) {
282+
if (false !== $result && !$result instanceof Error) {
282283
$result = $carrier->processAdditionalValidation($request);
283284
}
284285
if (!$result) {
@@ -287,7 +288,7 @@ private function prepareCarrier(string $carrierCode, RateRequest $request): Abst
287288
* if the delivery country is not within specific countries
288289
*/
289290
throw new \RuntimeException('Cannot collect rates for given request');
290-
} elseif ($result instanceof \Magento\Quote\Model\Quote\Address\RateResult\Error) {
291+
} elseif ($result instanceof Error) {
291292
$this->getResult()->append($result);
292293
throw new \RuntimeException('Error occurred while preparing a carrier');
293294
}

app/code/Magento/Shipping/Test/Unit/Model/Rate/PackageResultTest.php

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ protected function setUp()
5151
->disableOriginalConstructor()
5252
->getMock();
5353
$errorMock = $this->getMockBuilder(Error::class)->disableOriginalConstructor()->getMock();
54-
$errorMock->expects($this->any())->method('getErrorMessage')->willReturn('error message');
55-
$this->errorFactory->expects($this->any())->method('create')->willReturn($errorMock);
54+
$errorMock->method('getErrorMessage')->willReturn('error message');
55+
$this->errorFactory->method('create')->willReturn($errorMock);
5656

5757
$this->result = new PackageResult($this->storeManager, $this->errorFactory);
5858
}
@@ -78,10 +78,9 @@ public function testComposing(): void
7878
->setMethods(['getMethod', 'getPrice', 'setPrice'])
7979
->getMock();
8080
$price1 = 3;
81-
$rate1->expects($this->any())->method('getMethod')->willReturn('method');
82-
$rate1->expects($this->any())->method('getPrice')->willReturnReference($price1);
83-
$rate1->expects($this->any())
84-
->method('setPrice')
81+
$rate1->method('getMethod')->willReturn('method');
82+
$rate1->method('getPrice')->willReturnReference($price1);
83+
$rate1->method('setPrice')
8584
->willReturnCallback(
8685
function ($price) use (&$price1) {
8786
$price1 = $price;
@@ -91,7 +90,7 @@ function ($price) use (&$price1) {
9190
$result1 = $this->getMockBuilder(Result::class)
9291
->disableOriginalConstructor()
9392
->getMock();
94-
$result1->expects($this->any())->method('getAllRates')->willReturn([$rate1]);
93+
$result1->method('getAllRates')->willReturn([$rate1]);
9594
$result1->expects($this->once())
9695
->method('updateRatePrice')
9796
->with(2)
@@ -106,18 +105,17 @@ function () use (&$price1) {
106105
->setMethods(['getMethod', 'getPrice', 'setPrice'])
107106
->getMock();
108107
$price2 = 4;
109-
$rate2->expects($this->any())->method('getMethod')->willReturn('method');
110-
$rate2->expects($this->any())->method('getPrice')->willReturnReference($price2);
111-
$rate2->expects($this->any())
112-
->method('setPrice')
108+
$rate2->method('getMethod')->willReturn('method');
109+
$rate2->method('getPrice')->willReturnReference($price2);
110+
$rate2->method('setPrice')
113111
->willReturnCallback(
114112
function ($price) use (&$price2) {
115113
$price2 = $price;
116114
}
117115
);
118116
/** @var Result|MockObject $result2 */
119117
$result2 = $this->getMockBuilder(Result::class)->disableOriginalConstructor()->getMock();
120-
$result2->expects($this->any())->method('getAllRates')->willReturn([$rate2]);
118+
$result2->method('getAllRates')->willReturn([$rate2]);
121119
$result2->expects($this->once())
122120
->method('updateRatePrice')
123121
->with(3)
@@ -147,10 +145,9 @@ public function testAppendSameReference(): void
147145
->setMethods(['getMethod', 'getPrice', 'setPrice'])
148146
->getMock();
149147
$price1 = 3;
150-
$rate1->expects($this->any())->method('getMethod')->willReturn('method');
151-
$rate1->expects($this->any())->method('getPrice')->willReturnReference($price1);
152-
$rate1->expects($this->any())
153-
->method('setPrice')
148+
$rate1->method('getMethod')->willReturn('method');
149+
$rate1->method('getPrice')->willReturnReference($price1);
150+
$rate1->method('setPrice')
154151
->willReturnCallback(
155152
function ($price) use (&$price1) {
156153
$price1 = $price;
@@ -160,7 +157,7 @@ function ($price) use (&$price1) {
160157
$result1 = $this->getMockBuilder(Result::class)
161158
->disableOriginalConstructor()
162159
->getMock();
163-
$result1->expects($this->any())->method('getAllRates')->willReturn([$rate1]);
160+
$result1->method('getAllRates')->willReturn([$rate1]);
164161

165162
$this->result->appendPackageResult($result1, 1);
166163
$this->result->appendPackageResult($result1, 2);

dev/tests/integration/testsuite/Magento/Dhl/Model/CarrierTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
class CarrierTest extends \PHPUnit\Framework\TestCase
2626
{
2727
/**
28-
* @var \Magento\Dhl\Model\Carrier
28+
* @var Carrier
2929
*/
3030
private $dhlCarrier;
3131

@@ -49,8 +49,8 @@ class CarrierTest extends \PHPUnit\Framework\TestCase
4949
*/
5050
protected function setUp()
5151
{
52-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
53-
$this->dhlCarrier = $objectManager->get(\Magento\Dhl\Model\Carrier::class);
52+
$objectManager = Bootstrap::getObjectManager();
53+
$this->dhlCarrier = $objectManager->get(Carrier::class);
5454
$this->httpClient = $objectManager->get(AsyncClientInterface::class);
5555
$this->config = $objectManager->get(ReinitableConfigInterface::class);
5656
$this->restoreCountry = $this->config->getValue('shipping/origin/country_id', 'store', 'default_store');

0 commit comments

Comments
 (0)