@@ -143,10 +143,6 @@ protected function setUp(): void
143143 ->disableOriginalConstructor ()
144144 ->getMockForAbstractClass ();
145145
146- $ this ->scope ->expects ($ this ->any ())
147- ->method ('getValue ' )
148- ->willReturnCallback ([$ this , 'scopeConfigGetValue ' ]);
149-
150146 $ countryFactory = $ this ->getCountryFactory ();
151147 $ rateFactory = $ this ->getRateFactory ();
152148 $ storeManager = $ this ->getStoreManager ();
@@ -254,6 +250,7 @@ public function testRequestToShipmentExceptionNoPackages(): void
254250 /**
255251 * @return void
256252 * @throws LocalizedException
253+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
257254 */
258255 public function testRequestToShipmentSuccess (): void
259256 {
@@ -293,6 +290,11 @@ public function testRequestToShipmentSuccess(): void
293290 ];
294291 $ storeId = 1 ;
295292 $ phoneNumber = '1234567890 ' ;
293+
294+ $ this ->scope ->expects ($ this ->any ())
295+ ->method ('getValue ' )
296+ ->willReturnCallback ([$ this , 'scopeConfigGetValue ' ]);
297+
296298 $ request ->expects ($ this ->once ())->method ('getPackages ' )->willReturn ($ packages );
297299 $ request ->expects ($ this ->exactly (3 ))->method ('getStoreId ' )->willReturn ($ storeId );
298300 $ request ->expects ($ this ->once ())->method ('setPackageId ' );
@@ -355,6 +357,10 @@ public function testRequestToShipmentSuccess(): void
355357
356358 public function testSetRequestWithoutCity (): void
357359 {
360+ $ this ->scope ->expects ($ this ->any ())
361+ ->method ('getValue ' )
362+ ->willReturnCallback ([$ this , 'scopeConfigGetValue ' ]);
363+
358364 $ request = $ this ->getMockBuilder (RateRequest::class)
359365 ->disableOriginalConstructor ()
360366 ->addMethods (['getDestCity ' ])
@@ -367,6 +373,10 @@ public function testSetRequestWithoutCity(): void
367373
368374 public function testSetRequestWithCity (): void
369375 {
376+ $ this ->scope ->expects ($ this ->any ())
377+ ->method ('getValue ' )
378+ ->willReturnCallback ([$ this , 'scopeConfigGetValue ' ]);
379+
370380 $ request = $ this ->getMockBuilder (RateRequest::class)
371381 ->disableOriginalConstructor ()
372382 ->addMethods (['getDestCity ' ])
@@ -391,8 +401,33 @@ public function scopeConfigGetValue(string $path): int|string|null
391401 'carriers/fedex/debug ' => 1 ,
392402 'carriers/fedex/api_key ' => 'TestApiKey ' ,
393403 '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 ' ,
394429 '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/ '
396431 ];
397432
398433 return $ pathMap [$ path ] ?? null ;
@@ -417,6 +452,10 @@ public function testCollectRatesRateAmountOriginBased(
417452 ->method ('isSetFlag ' )
418453 ->willReturn (true );
419454
455+ $ this ->scope ->expects ($ this ->any ())
456+ ->method ('getValue ' )
457+ ->willReturnCallback ([$ this , 'scopeConfigGetValue ' ]);
458+
420459 $ accessTokenResponse = $ this ->getAccessToken ();
421460 $ rateResponse = $ this ->getRateResponse ($ amount , $ currencyCode , $ rateType );
422461
@@ -515,6 +554,10 @@ public function testCollectRatesErrorMessage(): void
515554 ->method ('isSetFlag ' )
516555 ->willReturn (false );
517556
557+ $ this ->scope ->expects ($ this ->any ())
558+ ->method ('getValue ' )
559+ ->willReturnCallback ([$ this , 'scopeConfigGetValue ' ]);
560+
518561 $ this ->error ->expects ($ this ->once ())
519562 ->method ('setCarrier ' )
520563 ->with ('fedex ' );
@@ -893,14 +936,25 @@ public function getAccessToken(): array
893936 * @param string $shipTimeStamp
894937 * @param string $expectedDate
895938 * @param string $expectedTime
939+ * @param bool $trackingEnabled
896940 * @dataProvider shipDateDataProvider
897941 */
898- public function testGetTracking ($ tracking , $ shipTimeStamp , $ expectedDate , $ expectedTime ): void
942+ public function testGetTracking ($ tracking , $ shipTimeStamp , $ expectedDate , $ expectedTime, $ trackingEnabled ): void
899943 {
900944 $ trackRequest = $ this ->getTrackRequest ($ tracking );
901945 $ trackResponse = $ this ->getTrackResponse ($ shipTimeStamp , $ expectedDate , $ expectedTime );
902946 $ accessTokenResponse = $ this ->getAccessToken ();
903947
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+
904958 $ this ->serializer ->method ('serialize ' )->willReturn (json_encode ($ trackRequest ));
905959 $ this ->serializer ->expects ($ this ->any ())
906960 ->method ('unserialize ' )
@@ -954,50 +1008,67 @@ public static function shipDateDataProvider(): array
9541008 'shipTimeStamp ' => '2020-08-15T02:06:35+03:00 ' ,
9551009 'expectedDate ' => '2014-01-09 ' ,
9561010 '18:31:00 ' ,
957- 0 ,
1011+ false ,
1012+ 0
9581013 ],
9591014 'tracking1-again ' => [
9601015 'tracking1 ' ,
9611016 'shipTimeStamp ' => '2014-01-09T02:06:35+03:00 ' ,
9621017 'expectedDate ' => '2014-01-09 ' ,
9631018 '18:31:00 ' ,
964- 0 ,
1019+ false ,
1020+ 0
9651021 ],
9661022 'tracking2 ' => [
9671023 'tracking2 ' ,
9681024 'shipTimeStamp ' => '2014-01-09T02:06:35+03:00 ' ,
9691025 'expectedDate ' => '2014-01-09 ' ,
9701026 '23:06:35 ' ,
1027+ false ,
1028+ 0
9711029 ],
9721030 'tracking3 ' => [
9731031 'tracking3 ' ,
9741032 'shipTimeStamp ' => '2014-01-09T14:06:35 ' ,
9751033 'expectedDate ' => '2014-01-09 ' ,
9761034 '18:31:00 ' ,
1035+ false ,
1036+ 0
9771037 ],
9781038 'tracking4 ' => [
9791039 'tracking4 ' ,
9801040 'shipTimeStamp ' => '2016-08-05 14:06:35 ' ,
9811041 'expectedDate ' => null ,
982- null ,
1042+ '' ,
1043+ false ,
9831044 ],
9841045 'tracking5 ' => [
9851046 'tracking5 ' ,
9861047 'shipTimeStamp ' => '2016-08-05 14:06:35+00:00 ' ,
9871048 'expectedDate ' => null ,
988- null ,
1049+ '' ,
1050+ false ,
9891051 ],
9901052 'tracking6 ' => [
9911053 'tracking6 ' ,
9921054 'shipTimeStamp ' => '2016-08-05 ' ,
9931055 'expectedDate ' => null ,
994- null ,
1056+ '' ,
1057+ false ,
9951058 ],
9961059 'tracking7 ' => [
9971060 'tracking7 ' ,
9981061 'shipTimeStamp ' => '2016/08/05 ' ,
9991062 '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
10011072 ],
10021073 ];
10031074 }
0 commit comments