Skip to content

Commit 8b54f8a

Browse files
committed
AC-9138::Fedex Ship API upgrade from SOAP to REST - Fix PHP Unit and Static test
1 parent 59bcd8c commit 8b54f8a

File tree

5 files changed

+96
-43
lines changed

5 files changed

+96
-43
lines changed

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

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
<?php
2-
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
2+
/************************************************************************
3+
*
4+
* ADOBE CONFIDENTIAL
5+
* ___________________
6+
*
7+
* Copyright 2014 Adobe
8+
* All Rights Reserved.
9+
*
10+
* NOTICE: All information contained herein is, and remains
11+
* the property of Adobe and its suppliers, if any. The intellectual
12+
* and technical concepts contained herein are proprietary to Adobe
13+
* and its suppliers and are protected by all applicable intellectual
14+
* property laws, including trade secret and copyright laws.
15+
* Dissemination of this information or reproduction of this material
16+
* is strictly forbidden unless prior written permission is obtained
17+
* from Adobe.
18+
* ************************************************************************
519
*/
620

721
namespace Magento\Fedex\Model;
@@ -153,12 +167,6 @@ class Carrier extends AbstractCarrierOnline implements \Magento\Shipping\Model\C
153167
'Key', 'Password', 'MeterNumber',
154168
];
155169

156-
/**
157-
* Version of tracking service
158-
* @var int
159-
*/
160-
private static $trackServiceVersion = 10;
161-
162170
/**
163171
* @var Json
164172
*/
@@ -467,7 +475,7 @@ protected function _formRateRequest($purpose) : array
467475
protected function _doRatesRequest($purpose) : mixed
468476
{
469477
$response = null;
470-
$accessToken = $this->_getAccessToken(null);
478+
$accessToken = $this->_getAccessToken();
471479
if (empty($accessToken)) {
472480
return null;
473481
}
@@ -1033,8 +1041,10 @@ protected function _getTrackingInformation($tracking) : void
10331041
$this->_debug($debugData);
10341042
$this->_parseTrackingResponse($tracking, $response);
10351043
} else {
1036-
$this->appendTrackingError($tracking, __('Authorization Error.
1037-
No Access Token found with given credentials.'));
1044+
$this->appendTrackingError(
1045+
$tracking,
1046+
__('Authorization Error. No Access Token found with given credentials.')
1047+
);
10381048
return;
10391049
}
10401050
}
@@ -1326,9 +1336,9 @@ protected function _doShipmentRequest(\Magento\Framework\DataObject $request) :
13261336
$this->_prepareShipmentRequest($request);
13271337
$result = new \Magento\Framework\DataObject();
13281338
$response = null;
1329-
$accessToken = $this->_getAccessToken(null);
1339+
$accessToken = $this->_getAccessToken();
13301340
if (empty($accessToken)) {
1331-
return $result->setErrors('No access token found.');
1341+
return $result->setErrors(__('Authorization Error. No Access Token found with given credentials.'));
13321342
}
13331343

13341344
$requestClient = $this->_formShipmentRequest($request);
@@ -1401,9 +1411,10 @@ private function getPackagingLabel($pieceResponses) : string
14011411
*/
14021412
public function rollBack($data): bool
14031413
{
1404-
$accessToken = $this->_getAccessToken(null);
1414+
$accessToken = $this->_getAccessToken();
14051415
if (empty($accessToken)) {
1406-
return $result->setErrors('No acccess token found.');
1416+
$this->_debug('Authorization Error. No Access Token found with given credentials.');
1417+
return false;
14071418
}
14081419

14091420
$requestData['accountNumber'] = ['value' => $this->getConfigData('account')];

app/code/Magento/Fedex/Model/Source/PickupType.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<?php
22
/************************************************************************
3-
* Copyright 2014 Adobe
3+
*
4+
* ADOBE CONFIDENTIAL
5+
* ___________________
6+
*
7+
* Copyright 2023 Adobe
48
* All Rights Reserved.
59
*
610
* NOTICE: All information contained herein is, and remains

app/code/Magento/Fedex/Test/Unit/Model/CarrierTest.php

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
<?php
2-
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
2+
/************************************************************************
3+
*
4+
* ADOBE CONFIDENTIAL
5+
* ___________________
6+
*
7+
* Copyright 2015 Adobe
8+
* All Rights Reserved.
9+
*
10+
* NOTICE: All information contained herein is, and remains
11+
* the property of Adobe and its suppliers, if any. The intellectual
12+
* and technical concepts contained herein are proprietary to Adobe
13+
* and its suppliers and are protected by all applicable intellectual
14+
* property laws, including trade secret and copyright laws.
15+
* Dissemination of this information or reproduction of this material
16+
* is strictly forbidden unless prior written permission is obtained
17+
* from Adobe.
18+
* ************************************************************************
519
*/
620

721
declare(strict_types=1);
@@ -45,6 +59,7 @@
4559
use Psr\Log\LoggerInterface;
4660
use Magento\Framework\HTTP\Client\CurlFactory;
4761
use Magento\Framework\HTTP\Client\Curl;
62+
use Magento\Framework\Url\DecoderInterface;
4863

4964
/**
5065
* CarrierTest contains units test for Fedex carrier methods
@@ -93,11 +108,6 @@ class CarrierTest extends TestCase
93108
*/
94109
private $result;
95110

96-
/**
97-
* @var \SoapClient|MockObject
98-
*/
99-
private $soapClient;
100-
101111
/**
102112
* @var Json|MockObject
103113
*/
@@ -123,6 +133,11 @@ class CarrierTest extends TestCase
123133
*/
124134
private $curlClient;
125135

136+
/**
137+
* @var DecoderInterface
138+
*/
139+
private $decoderInterface;
140+
126141
/**
127142
* @return void
128143
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
@@ -180,10 +195,6 @@ protected function setUp(): void
180195
->disableOriginalConstructor()
181196
->getMock();
182197

183-
$reader = $this->getMockBuilder(Reader::class)
184-
->disableOriginalConstructor()
185-
->getMock();
186-
187198
$this->serializer = $this->getMockBuilder(Json::class)
188199
->disableOriginalConstructor()
189200
->getMock();
@@ -200,6 +211,11 @@ protected function setUp(): void
200211
->setMethods(['setHeaders', 'getBody', 'post'])
201212
->getMock();
202213

214+
$this->decoderInterface = $this->getMockBuilder(DecoderInterface::class)
215+
->disableOriginalConstructor()
216+
->setMethods(['decode'])
217+
->getMock();
218+
203219
$this->carrier = $this->getMockBuilder(Carrier::class)
204220
->setMethods(['_createSoapClient'])
205221
->setConstructorArgs(
@@ -220,19 +236,13 @@ protected function setUp(): void
220236
'directoryData' => $data,
221237
'stockRegistry' => $stockRegistry,
222238
'storeManager' => $storeManager,
223-
'configReader' => $reader,
224239
'productCollectionFactory' => $collectionFactory,
225240
'curlFactory' => $this->curlFactory,
241+
'decoderInterface' => $this->decoderInterface,
226242
'data' => [],
227243
'serializer' => $this->serializer,
228244
]
229245
)->getMock();
230-
$this->soapClient = $this->getMockBuilder(\SoapClient::class)
231-
->disableOriginalConstructor()
232-
->setMethods(['getRates', 'track'])
233-
->getMock();
234-
$this->carrier->method('_createSoapClient')
235-
->willReturn($this->soapClient);
236246
}
237247

238248
public function testSetRequestWithoutCity()
@@ -769,7 +779,7 @@ public function getAccessToken() : array
769779
$this->curlFactory->expects($this->any())->method('create')->willReturn($this->curlClient);
770780
$this->curlClient->expects($this->any())->method('setHeaders')->willReturnSelf();
771781
$this->curlClient->expects($this->any())->method('post')->willReturnSelf();
772-
$this->curlClient->expects($this->any())->method('getBody')->willReturnSelf();
782+
$this->curlClient->expects($this->any())->method('getBody')->willReturn(json_encode($accessTokenResponse));
773783
return $accessTokenResponse;
774784
}
775785

app/code/Magento/Fedex/etc/adminhtml/system.xml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
<?xml version="1.0"?>
22
<!--
3-
/**
4-
* Copyright © Magento, Inc. All rights reserved.
5-
* See COPYING.txt for license details.
3+
/************************************************************************
4+
*
5+
* ADOBE CONFIDENTIAL
6+
* ___________________
7+
*
8+
* Copyright 2014 Adobe
9+
* All Rights Reserved.
10+
*
11+
* NOTICE: All information contained herein is, and remains
12+
* the property of Adobe and its suppliers, if any. The intellectual
13+
* and technical concepts contained herein are proprietary to Adobe
14+
* and its suppliers and are protected by all applicable intellectual
15+
* property laws, including trade secret and copyright laws.
16+
* Dissemination of this information or reproduction of this material
17+
* is strictly forbidden unless prior written permission is obtained
18+
* from Adobe.
19+
* ************************************************************************
620
*/
721
-->
822
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">

app/code/Magento/Fedex/etc/config.xml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
<?xml version="1.0"?>
22
<!--
3-
/**
4-
* Copyright © Magento, Inc. All rights reserved.
5-
* See COPYING.txt for license details.
3+
/************************************************************************
4+
*
5+
* ADOBE CONFIDENTIAL
6+
* ___________________
7+
*
8+
* Copyright 2014 Adobe
9+
* All Rights Reserved.
10+
*
11+
* NOTICE: All information contained herein is, and remains
12+
* the property of Adobe and its suppliers, if any. The intellectual
13+
* and technical concepts contained herein are proprietary to Adobe
14+
* and its suppliers and are protected by all applicable intellectual
15+
* property laws, including trade secret and copyright laws.
16+
* Dissemination of this information or reproduction of this material
17+
* is strictly forbidden unless prior written permission is obtained
18+
* from Adobe.
19+
* ************************************************************************
620
*/
721
-->
822
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">

0 commit comments

Comments
 (0)