@@ -143,10 +143,6 @@ protected function setUp(): void
143
143
->disableOriginalConstructor ()
144
144
->getMockForAbstractClass ();
145
145
146
- $ this ->scope ->expects ($ this ->any ())
147
- ->method ('getValue ' )
148
- ->willReturnCallback ([$ this , 'scopeConfigGetValue ' ]);
149
-
150
146
$ countryFactory = $ this ->getCountryFactory ();
151
147
$ rateFactory = $ this ->getRateFactory ();
152
148
$ storeManager = $ this ->getStoreManager ();
@@ -254,6 +250,7 @@ public function testRequestToShipmentExceptionNoPackages(): void
254
250
/**
255
251
* @return void
256
252
* @throws LocalizedException
253
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
257
254
*/
258
255
public function testRequestToShipmentSuccess (): void
259
256
{
@@ -293,6 +290,11 @@ public function testRequestToShipmentSuccess(): void
293
290
];
294
291
$ storeId = 1 ;
295
292
$ phoneNumber = '1234567890 ' ;
293
+
294
+ $ this ->scope ->expects ($ this ->any ())
295
+ ->method ('getValue ' )
296
+ ->willReturnCallback ([$ this , 'scopeConfigGetValue ' ]);
297
+
296
298
$ request ->expects ($ this ->once ())->method ('getPackages ' )->willReturn ($ packages );
297
299
$ request ->expects ($ this ->exactly (3 ))->method ('getStoreId ' )->willReturn ($ storeId );
298
300
$ request ->expects ($ this ->once ())->method ('setPackageId ' );
@@ -355,6 +357,10 @@ public function testRequestToShipmentSuccess(): void
355
357
356
358
public function testSetRequestWithoutCity (): void
357
359
{
360
+ $ this ->scope ->expects ($ this ->any ())
361
+ ->method ('getValue ' )
362
+ ->willReturnCallback ([$ this , 'scopeConfigGetValue ' ]);
363
+
358
364
$ request = $ this ->getMockBuilder (RateRequest::class)
359
365
->disableOriginalConstructor ()
360
366
->addMethods (['getDestCity ' ])
@@ -367,6 +373,10 @@ public function testSetRequestWithoutCity(): void
367
373
368
374
public function testSetRequestWithCity (): void
369
375
{
376
+ $ this ->scope ->expects ($ this ->any ())
377
+ ->method ('getValue ' )
378
+ ->willReturnCallback ([$ this , 'scopeConfigGetValue ' ]);
379
+
370
380
$ request = $ this ->getMockBuilder (RateRequest::class)
371
381
->disableOriginalConstructor ()
372
382
->addMethods (['getDestCity ' ])
@@ -391,8 +401,33 @@ public function scopeConfigGetValue(string $path): int|string|null
391
401
'carriers/fedex/debug ' => 1 ,
392
402
'carriers/fedex/api_key ' => 'TestApiKey ' ,
393
403
'carriers/fedex/secret_key ' => 'TestSecretKey ' ,
404
+ 'carriers/fedex/enabled_tracking_api ' => 0 ,
405
+ 'carriers/fedex/rest_sandbox_webservices_url ' => 'https://rest.sandbox.url/ ' ,
406
+ 'carriers/fedex/rest_production_webservices_url ' => 'https://rest.production.url/ '
407
+ ];
408
+
409
+ return $ pathMap [$ path ] ?? null ;
410
+ }
411
+
412
+ /**
413
+ * Callback function, emulates getValue function for tracking api flow
414
+ *
415
+ * @param string $path
416
+ * @return int|string|null
417
+ */
418
+ public function scopeConfigGetValueForTracking (string $ path ): int |string |null
419
+ {
420
+ $ pathMap = [
421
+ 'carriers/fedex/showmethod ' => 1 ,
422
+ 'carriers/fedex/allowed_methods ' => 'ServiceType ' ,
423
+ 'carriers/fedex/debug ' => 1 ,
424
+ 'carriers/fedex/api_key ' => 'TestApiKey ' ,
425
+ 'carriers/fedex/secret_key ' => 'TestSecretKey ' ,
426
+ 'carriers/fedex/enabled_tracking_api ' => 1 ,
427
+ 'carriers/fedex/tracking_api_key ' => 'TestTrackingApiKey ' ,
428
+ 'carriers/fedex/tracking_api_secret_key ' => 'TestTrackingSecretKey ' ,
394
429
'carriers/fedex/rest_sandbox_webservices_url ' => 'https://rest.sandbox.url/ ' ,
395
- 'carriers/fedex/rest_production_webservices_url ' => 'https://rest.production.url/ ' ,
430
+ 'carriers/fedex/rest_production_webservices_url ' => 'https://rest.production.url/ '
396
431
];
397
432
398
433
return $ pathMap [$ path ] ?? null ;
@@ -417,6 +452,10 @@ public function testCollectRatesRateAmountOriginBased(
417
452
->method ('isSetFlag ' )
418
453
->willReturn (true );
419
454
455
+ $ this ->scope ->expects ($ this ->any ())
456
+ ->method ('getValue ' )
457
+ ->willReturnCallback ([$ this , 'scopeConfigGetValue ' ]);
458
+
420
459
$ accessTokenResponse = $ this ->getAccessToken ();
421
460
$ rateResponse = $ this ->getRateResponse ($ amount , $ currencyCode , $ rateType );
422
461
@@ -515,6 +554,10 @@ public function testCollectRatesErrorMessage(): void
515
554
->method ('isSetFlag ' )
516
555
->willReturn (false );
517
556
557
+ $ this ->scope ->expects ($ this ->any ())
558
+ ->method ('getValue ' )
559
+ ->willReturnCallback ([$ this , 'scopeConfigGetValue ' ]);
560
+
518
561
$ this ->error ->expects ($ this ->once ())
519
562
->method ('setCarrier ' )
520
563
->with ('fedex ' );
@@ -893,14 +936,25 @@ public function getAccessToken(): array
893
936
* @param string $shipTimeStamp
894
937
* @param string $expectedDate
895
938
* @param string $expectedTime
939
+ * @param bool $trackingEnabled
896
940
* @dataProvider shipDateDataProvider
897
941
*/
898
- public function testGetTracking ($ tracking , $ shipTimeStamp , $ expectedDate , $ expectedTime ): void
942
+ public function testGetTracking ($ tracking , $ shipTimeStamp , $ expectedDate , $ expectedTime, $ trackingEnabled ): void
899
943
{
900
944
$ trackRequest = $ this ->getTrackRequest ($ tracking );
901
945
$ trackResponse = $ this ->getTrackResponse ($ shipTimeStamp , $ expectedDate , $ expectedTime );
902
946
$ accessTokenResponse = $ this ->getAccessToken ();
903
947
948
+ if ($ trackingEnabled ) {
949
+ $ this ->scope ->expects ($ this ->atLeast (1 ))
950
+ ->method ('getValue ' )
951
+ ->willReturnCallback ([$ this , 'scopeConfigGetValueForTracking ' ]);
952
+ } else {
953
+ $ this ->scope ->expects ($ this ->any ())
954
+ ->method ('getValue ' )
955
+ ->willReturnCallback ([$ this , 'scopeConfigGetValue ' ]);
956
+ }
957
+
904
958
$ this ->serializer ->method ('serialize ' )->willReturn (json_encode ($ trackRequest ));
905
959
$ this ->serializer ->expects ($ this ->any ())
906
960
->method ('unserialize ' )
@@ -954,50 +1008,67 @@ public static function shipDateDataProvider(): array
954
1008
'shipTimeStamp ' => '2020-08-15T02:06:35+03:00 ' ,
955
1009
'expectedDate ' => '2014-01-09 ' ,
956
1010
'18:31:00 ' ,
957
- 0 ,
1011
+ false ,
1012
+ 0
958
1013
],
959
1014
'tracking1-again ' => [
960
1015
'tracking1 ' ,
961
1016
'shipTimeStamp ' => '2014-01-09T02:06:35+03:00 ' ,
962
1017
'expectedDate ' => '2014-01-09 ' ,
963
1018
'18:31:00 ' ,
964
- 0 ,
1019
+ false ,
1020
+ 0
965
1021
],
966
1022
'tracking2 ' => [
967
1023
'tracking2 ' ,
968
1024
'shipTimeStamp ' => '2014-01-09T02:06:35+03:00 ' ,
969
1025
'expectedDate ' => '2014-01-09 ' ,
970
1026
'23:06:35 ' ,
1027
+ false ,
1028
+ 0
971
1029
],
972
1030
'tracking3 ' => [
973
1031
'tracking3 ' ,
974
1032
'shipTimeStamp ' => '2014-01-09T14:06:35 ' ,
975
1033
'expectedDate ' => '2014-01-09 ' ,
976
1034
'18:31:00 ' ,
1035
+ false ,
1036
+ 0
977
1037
],
978
1038
'tracking4 ' => [
979
1039
'tracking4 ' ,
980
1040
'shipTimeStamp ' => '2016-08-05 14:06:35 ' ,
981
1041
'expectedDate ' => null ,
982
- null ,
1042
+ '' ,
1043
+ false ,
983
1044
],
984
1045
'tracking5 ' => [
985
1046
'tracking5 ' ,
986
1047
'shipTimeStamp ' => '2016-08-05 14:06:35+00:00 ' ,
987
1048
'expectedDate ' => null ,
988
- null ,
1049
+ '' ,
1050
+ false ,
989
1051
],
990
1052
'tracking6 ' => [
991
1053
'tracking6 ' ,
992
1054
'shipTimeStamp ' => '2016-08-05 ' ,
993
1055
'expectedDate ' => null ,
994
- null ,
1056
+ '' ,
1057
+ false ,
995
1058
],
996
1059
'tracking7 ' => [
997
1060
'tracking7 ' ,
998
1061
'shipTimeStamp ' => '2016/08/05 ' ,
999
1062
'expectedDate ' => null ,
1000
- null
1063
+ '' ,
1064
+ false ,
1065
+ ],
1066
+ 'tracking8 ' => [
1067
+ 'tracking8 ' ,
1068
+ 'shipTimestamp ' => '2024-09-19T02:06:35+03:00 ' ,
1069
+ 'expectedDate ' => '2024-09-21 ' ,
1070
+ '18:31:00 ' ,
1071
+ true
1001
1072
],
1002
1073
];
1003
1074
}
0 commit comments