@@ -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 ();
@@ -293,6 +289,11 @@ public function testRequestToShipmentSuccess(): void
293
289
];
294
290
$ storeId = 1 ;
295
291
$ phoneNumber = '1234567890 ' ;
292
+
293
+ $ this ->scope ->expects ($ this ->any ())
294
+ ->method ('getValue ' )
295
+ ->willReturnCallback ([$ this , 'scopeConfigGetValue ' ]);
296
+
296
297
$ request ->expects ($ this ->once ())->method ('getPackages ' )->willReturn ($ packages );
297
298
$ request ->expects ($ this ->exactly (3 ))->method ('getStoreId ' )->willReturn ($ storeId );
298
299
$ request ->expects ($ this ->once ())->method ('setPackageId ' );
@@ -355,6 +356,10 @@ public function testRequestToShipmentSuccess(): void
355
356
356
357
public function testSetRequestWithoutCity (): void
357
358
{
359
+ $ this ->scope ->expects ($ this ->any ())
360
+ ->method ('getValue ' )
361
+ ->willReturnCallback ([$ this , 'scopeConfigGetValue ' ]);
362
+
358
363
$ request = $ this ->getMockBuilder (RateRequest::class)
359
364
->disableOriginalConstructor ()
360
365
->addMethods (['getDestCity ' ])
@@ -367,6 +372,10 @@ public function testSetRequestWithoutCity(): void
367
372
368
373
public function testSetRequestWithCity (): void
369
374
{
375
+ $ this ->scope ->expects ($ this ->any ())
376
+ ->method ('getValue ' )
377
+ ->willReturnCallback ([$ this , 'scopeConfigGetValue ' ]);
378
+
370
379
$ request = $ this ->getMockBuilder (RateRequest::class)
371
380
->disableOriginalConstructor ()
372
381
->addMethods (['getDestCity ' ])
@@ -391,8 +400,31 @@ public function scopeConfigGetValue(string $path): int|string|null
391
400
'carriers/fedex/debug ' => 1 ,
392
401
'carriers/fedex/api_key ' => 'TestApiKey ' ,
393
402
'carriers/fedex/secret_key ' => 'TestSecretKey ' ,
403
+ 'carriers/fedex/enabled_tracking_api ' => 0 ,
404
+ 'carriers/fedex/rest_sandbox_webservices_url ' => 'https://rest.sandbox.url/ ' ,
405
+ 'carriers/fedex/rest_production_webservices_url ' => 'https://rest.production.url/ '
406
+ ];
407
+
408
+ return $ pathMap [$ path ] ?? null ;
409
+ }
410
+
411
+ /**
412
+ * @param string $path
413
+ * @return int|string|null
414
+ */
415
+ public function scopeConfigGetValueForTracking (string $ path ): int |string |null
416
+ {
417
+ $ pathMap = [
418
+ 'carriers/fedex/showmethod ' => 1 ,
419
+ 'carriers/fedex/allowed_methods ' => 'ServiceType ' ,
420
+ 'carriers/fedex/debug ' => 1 ,
421
+ 'carriers/fedex/api_key ' => 'TestApiKey ' ,
422
+ 'carriers/fedex/secret_key ' => 'TestSecretKey ' ,
423
+ 'carriers/fedex/enabled_tracking_api ' => 1 ,
424
+ 'carriers/fedex/tracking_api_key ' => 'TestTrackingApiKey ' ,
425
+ 'carriers/fedex/tracking_api_secret_key ' => 'TestTrackingSecretKey ' ,
394
426
'carriers/fedex/rest_sandbox_webservices_url ' => 'https://rest.sandbox.url/ ' ,
395
- 'carriers/fedex/rest_production_webservices_url ' => 'https://rest.production.url/ ' ,
427
+ 'carriers/fedex/rest_production_webservices_url ' => 'https://rest.production.url/ '
396
428
];
397
429
398
430
return $ pathMap [$ path ] ?? null ;
@@ -417,6 +449,10 @@ public function testCollectRatesRateAmountOriginBased(
417
449
->method ('isSetFlag ' )
418
450
->willReturn (true );
419
451
452
+ $ this ->scope ->expects ($ this ->any ())
453
+ ->method ('getValue ' )
454
+ ->willReturnCallback ([$ this , 'scopeConfigGetValue ' ]);
455
+
420
456
$ accessTokenResponse = $ this ->getAccessToken ();
421
457
$ rateResponse = $ this ->getRateResponse ($ amount , $ currencyCode , $ rateType );
422
458
@@ -503,6 +539,10 @@ public function testCollectRatesErrorMessage(): void
503
539
->method ('isSetFlag ' )
504
540
->willReturn (false );
505
541
542
+ $ this ->scope ->expects ($ this ->any ())
543
+ ->method ('getValue ' )
544
+ ->willReturnCallback ([$ this , 'scopeConfigGetValue ' ]);
545
+
506
546
$ this ->error ->expects ($ this ->once ())
507
547
->method ('setCarrier ' )
508
548
->with ('fedex ' );
@@ -881,14 +921,25 @@ public function getAccessToken(): array
881
921
* @param string $shipTimeStamp
882
922
* @param string $expectedDate
883
923
* @param string $expectedTime
924
+ * @param bool $trackingEnabled
884
925
* @dataProvider shipDateDataProvider
885
926
*/
886
- public function testGetTracking ($ tracking , $ shipTimeStamp , $ expectedDate , $ expectedTime ): void
927
+ public function testGetTracking ($ tracking , $ shipTimeStamp , $ expectedDate , $ expectedTime, $ trackingEnabled ): void
887
928
{
888
929
$ trackRequest = $ this ->getTrackRequest ($ tracking );
889
930
$ trackResponse = $ this ->getTrackResponse ($ shipTimeStamp , $ expectedDate , $ expectedTime );
890
931
$ accessTokenResponse = $ this ->getAccessToken ();
891
932
933
+ if ($ trackingEnabled ) {
934
+ $ this ->scope ->expects ($ this ->atLeast (1 ))
935
+ ->method ('getValue ' )
936
+ ->willReturnCallback ([$ this , 'scopeConfigGetValueForTracking ' ]);
937
+ } else {
938
+ $ this ->scope ->expects ($ this ->any ())
939
+ ->method ('getValue ' )
940
+ ->willReturnCallback ([$ this , 'scopeConfigGetValue ' ]);
941
+ }
942
+
892
943
$ this ->serializer ->method ('serialize ' )->willReturn (json_encode ($ trackRequest ));
893
944
$ this ->serializer ->expects ($ this ->any ())
894
945
->method ('unserialize ' )
@@ -942,50 +993,67 @@ public static function shipDateDataProvider(): array
942
993
'shipTimestamp ' => '2020-08-15T02:06:35+03:00 ' ,
943
994
'expectedDate ' => '2014-01-09 ' ,
944
995
'18:31:00 ' ,
945
- 0 ,
996
+ false ,
997
+ 0
946
998
],
947
999
'tracking1-again ' => [
948
1000
'tracking1 ' ,
949
1001
'shipTimestamp ' => '2014-01-09T02:06:35+03:00 ' ,
950
1002
'expectedDate ' => '2014-01-09 ' ,
951
1003
'18:31:00 ' ,
952
- 0 ,
1004
+ false ,
1005
+ 0
953
1006
],
954
1007
'tracking2 ' => [
955
1008
'tracking2 ' ,
956
1009
'shipTimestamp ' => '2014-01-09T02:06:35+03:00 ' ,
957
1010
'expectedDate ' => '2014-01-09 ' ,
958
1011
'23:06:35 ' ,
1012
+ false ,
1013
+ 0
959
1014
],
960
1015
'tracking3 ' => [
961
1016
'tracking3 ' ,
962
1017
'shipTimestamp ' => '2014-01-09T14:06:35 ' ,
963
1018
'expectedDate ' => '2014-01-09 ' ,
964
1019
'18:31:00 ' ,
1020
+ false ,
1021
+ 0
965
1022
],
966
1023
'tracking4 ' => [
967
1024
'tracking4 ' ,
968
1025
'shipTimestamp ' => '2016-08-05 14:06:35 ' ,
969
1026
'expectedDate ' => null ,
970
- null ,
1027
+ '' ,
1028
+ false ,
971
1029
],
972
1030
'tracking5 ' => [
973
1031
'tracking5 ' ,
974
1032
'shipTimestamp ' => '2016-08-05 14:06:35+00:00 ' ,
975
1033
'expectedDate ' => null ,
976
- null ,
1034
+ '' ,
1035
+ false ,
977
1036
],
978
1037
'tracking6 ' => [
979
1038
'tracking6 ' ,
980
1039
'shipTimestamp ' => '2016-08-05 ' ,
981
1040
'expectedDate ' => null ,
982
- null ,
1041
+ '' ,
1042
+ false ,
983
1043
],
984
1044
'tracking7 ' => [
985
1045
'tracking7 ' ,
986
1046
'shipTimestamp ' => '2016/08/05 ' ,
987
1047
'expectedDate ' => null ,
988
- null
1048
+ '' ,
1049
+ false ,
1050
+ ],
1051
+ 'tracking8 ' => [
1052
+ 'tracking8 ' ,
1053
+ 'shipTimestamp ' => '2024-09-19T02:06:35+03:00 ' ,
1054
+ 'expectedDate ' => '2024-09-21 ' ,
1055
+ '18:31:00 ' ,
1056
+ true
989
1057
],
990
1058
];
991
1059
}
0 commit comments