@@ -1074,6 +1074,79 @@ public function testGetCodeWithDropoffTypeNoCode(): void
10741074 $ this ->assertEquals (__ ('Regular Pickup ' ), $ result ['REGULAR_PICKUP ' ]);
10751075 }
10761076
1077+ /**
1078+ * Test get access token from cache
1079+ */
1080+ public function testCollectRatesWithCachedAccessToken (): void
1081+ {
1082+ $ apiKey = 'TestApiKey ' ;
1083+ $ secretKey = 'TestSecretKey ' ;
1084+ $ accessToken = 'CachedTestAccessToken ' ;
1085+ $ cacheKey = 'fedex_access_token_ ' . hash ('sha256 ' , $ apiKey . $ secretKey );
1086+ $ expiresAt = time () + 3600 ;
1087+ $ cachedData = json_encode ([
1088+ 'access_token ' => $ accessToken ,
1089+ 'expires_at ' => $ expiresAt
1090+ ]);
1091+ $ this ->scope ->expects ($ this ->any ())
1092+ ->method ('getValue ' )
1093+ ->willReturnCallback ([$ this , 'scopeConfigGetValue ' ]);
1094+ $ this ->scope ->expects ($ this ->exactly (2 ))
1095+ ->method ('isSetFlag ' )
1096+ ->willReturn (true );
1097+
1098+ $ this ->cacheMock ->expects ($ this ->once ())
1099+ ->method ('load ' )
1100+ ->with ($ cacheKey )
1101+ ->willReturn ($ cachedData );
1102+
1103+ $ rateResponseMock = [
1104+ 'output ' => [
1105+ 'rateReplyDetails ' => [
1106+ [
1107+ 'serviceType ' => 'FEDEX_GROUND ' ,
1108+ 'ratedShipmentDetails ' => [
1109+ [
1110+ 'totalNetCharge ' => '28.75 ' ,
1111+ 'currency ' => 'USD ' ,
1112+ 'ratedPackages ' => [
1113+ ['packageRateDetail ' => ['rateType ' => 'RATED_ACCOUNT_PACKAGE ' ]]
1114+ ]
1115+ ]
1116+ ]
1117+ ]
1118+ ]
1119+ ]
1120+ ];
1121+ $ this ->serializer ->expects ($ this ->once ())
1122+ ->method ('serialize ' )
1123+ ->willReturn (json_encode (['mocked_request ' => 'data ' ]));
1124+ $ this ->serializer ->expects ($ this ->once ())
1125+ ->method ('unserialize ' )
1126+ ->willReturn ($ rateResponseMock );
1127+ $ this ->curlFactory ->expects ($ this ->once ())
1128+ ->method ('create ' )
1129+ ->willReturn ($ this ->curlClient );
1130+ $ this ->curlClient ->expects ($ this ->once ())
1131+ ->method ('setHeaders ' )
1132+ ->willReturnSelf ();
1133+ $ this ->curlClient ->expects ($ this ->once ())
1134+ ->method ('post ' )
1135+ ->willReturnSelf ();
1136+ $ this ->curlClient ->expects ($ this ->once ())
1137+ ->method ('getBody ' )
1138+ ->willReturn (json_encode ($ rateResponseMock ));
1139+ $ request = $ this ->getMockBuilder (RateRequest::class)
1140+ ->addMethods (['getBaseCurrency ' , 'getPackageWeight ' ])
1141+ ->disableOriginalConstructor ()
1142+ ->getMock ();
1143+ $ request ->method ('getPackageWeight ' )
1144+ ->willReturn (10.0 );
1145+ $ result = $ this ->carrier ->collectRates ($ request );
1146+ $ this ->assertInstanceOf (RateResult::class, $ result );
1147+ $ rates = $ result ->getAllRates ();
1148+ $ this ->assertNotEmpty ($ rates );
1149+ }
10771150 /**
10781151 * Gets list of variations for testing ship date.
10791152 *
0 commit comments