Skip to content

Commit 152a180

Browse files
committed
Merge remote-tracking branch 'origin/MC-23024' into 2.4-develop-pr119
2 parents 63434d2 + c5b79d4 commit 152a180

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

app/code/Magento/Ups/Model/Carrier.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -807,21 +807,24 @@ protected function _getXmlQuotes()
807807
$httpResponse = $this->asyncHttpClient->request(
808808
new Request($url, Request::METHOD_POST, ['Content-Type' => 'application/xml'], $xmlRequest)
809809
);
810-
810+
$debugData['request'] = $xmlParams;
811811
return $this->deferredProxyFactory->create(
812812
[
813813
'deferred' => new CallbackDeferred(
814-
function () use ($httpResponse) {
814+
function () use ($httpResponse, $debugData) {
815815
$responseResult = null;
816816
$xmlResponse = '';
817817
try {
818818
$responseResult = $httpResponse->get();
819-
} catch (HttpException $exception) {
820-
$this->_logger->critical($exception);
819+
} catch (HttpException $e) {
820+
$debugData['result'] = ['error' => $e->getMessage(), 'code' => $e->getCode()];
821+
$this->_logger->critical($e);
821822
}
822823
if ($responseResult) {
823824
$xmlResponse = $responseResult->getStatusCode() >= 400 ? '' : $responseResult->getBody();
824825
}
826+
$debugData['result'] = $xmlResponse;
827+
$this->_debug($debugData);
825828

826829
return $this->_parseXmlResponse($xmlResponse);
827830
}
@@ -1125,6 +1128,7 @@ protected function _getXmlTracking($trackings)
11251128
/** @var HttpResponseDeferredInterface[] $trackingResponses */
11261129
$trackingResponses = [];
11271130
$tracking = '';
1131+
$debugData = [];
11281132
foreach ($trackings as $tracking) {
11291133
/**
11301134
* RequestOption==>'1' to request all activities
@@ -1141,7 +1145,7 @@ protected function _getXmlTracking($trackings)
11411145
<IncludeFreight>01</IncludeFreight>
11421146
</TrackRequest>
11431147
XMLAuth;
1144-
1148+
$debugData[$tracking] = ['request' => $this->filterDebugData($this->_xmlAccessRequest) . $xmlRequest];
11451149
$trackingResponses[$tracking] = $this->asyncHttpClient->request(
11461150
new Request(
11471151
$url,
@@ -1155,6 +1159,8 @@ protected function _getXmlTracking($trackings)
11551159
$httpResponse = $response->get();
11561160
$xmlResponse = $httpResponse->getStatusCode() >= 400 ? '' : $httpResponse->getBody();
11571161

1162+
$debugData[$tracking]['result'] = $xmlResponse;
1163+
$this->_debug($debugData);
11581164
$this->_parseXmlTrackingResponse($tracking, $xmlResponse);
11591165
}
11601166

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
use Magento\Quote\Model\Quote\Address\RateRequestFactory;
2020
use Magento\TestFramework\HTTP\AsyncClientInterfaceMock;
2121
use PHPUnit\Framework\TestCase;
22+
use PHPUnit\Framework\MockObject\MockObject;
2223
use Magento\Shipping\Model\Shipment\Request;
24+
use Psr\Log\LoggerInterface;
2325

2426
/**
2527
* Integration tests for Carrier model class
@@ -43,14 +45,32 @@ class CarrierTest extends TestCase
4345
*/
4446
private $config;
4547

48+
/**
49+
* @var LoggerInterface|MockObject
50+
*/
51+
private $loggerMock;
52+
53+
/**
54+
* @var string[]
55+
*/
56+
private $logs = [];
57+
4658
/**
4759
* @inheritDoc
4860
*/
4961
protected function setUp(): void
5062
{
51-
$this->carrier = Bootstrap::getObjectManager()->create(Carrier::class);
5263
$this->httpClient = Bootstrap::getObjectManager()->get(AsyncClientInterface::class);
5364
$this->config = Bootstrap::getObjectManager()->get(ReinitableConfigInterface::class);
65+
$this->logs = [];
66+
$this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
67+
$this->loggerMock->method('debug')
68+
->willReturnCallback(
69+
function (string $message) {
70+
$this->logs[] = $message;
71+
}
72+
);
73+
$this->carrier = Bootstrap::getObjectManager()->create(Carrier::class, ['logger' => $this->loggerMock]);
5474
}
5575

5676
/**
@@ -136,6 +156,7 @@ public function testCollectFreeRates()
136156
* @magentoConfigFixture default_store carriers/ups/username user
137157
* @magentoConfigFixture default_store carriers/ups/password pass
138158
* @magentoConfigFixture default_store carriers/ups/access_license_number acn
159+
* @magentoConfigFixture default_store carriers/ups/debug 1
139160
* @magentoConfigFixture default_store currency/options/allow GBP,USD,EUR
140161
* @magentoConfigFixture default_store currency/options/base GBP
141162
*/
@@ -172,6 +193,17 @@ public function testCollectRates(int $negotiable, int $tax, int $responseId, str
172193
$rates = $this->carrier->collectRates($request)->getAllRates();
173194
$this->assertEquals($price, $rates[0]->getPrice());
174195
$this->assertEquals($method, $rates[0]->getMethod());
196+
197+
$requestFound = false;
198+
foreach ($this->logs as $log) {
199+
if (mb_stripos($log, 'RatingServiceSelectionRequest') &&
200+
mb_stripos($log, 'RatingServiceSelectionResponse')
201+
) {
202+
$requestFound = true;
203+
break;
204+
}
205+
}
206+
$this->assertTrue($requestFound);
175207
}
176208

177209
/**
@@ -304,6 +336,7 @@ public function testRequestToShipment(): void
304336
* @magentoConfigFixture default_store carriers/ups/username user
305337
* @magentoConfigFixture default_store carriers/ups/password pass
306338
* @magentoConfigFixture default_store carriers/ups/access_license_number acn
339+
* @magentoConfigFixture default_store carriers/ups/debug 1
307340
* @magentoConfigFixture default_store currency/options/allow GBP,USD,EUR
308341
* @magentoConfigFixture default_store currency/options/base GBP
309342
*/

0 commit comments

Comments
 (0)