1212
1313namespace chillerlan \OAuthTest \Providers ;
1414
15- use chillerlan \HTTP \{Psr17 , Psr7 };
1615use chillerlan \HTTP \Psr7 \{Request , Response };
1716use chillerlan \OAuth \Core \{AccessToken , ClientCredentials , CSRFToken , OAuth2Interface , ProviderException , TokenRefresh };
1817use chillerlan \OAuth \OAuthException ;
1918
19+ use function chillerlan \HTTP \Psr17 \create_stream_from_input ;
20+ use function chillerlan \HTTP \Psr7 \get_json ;
21+
22+ use function explode , parse_str , parse_url , sleep , time ;
23+
24+ use const PHP_URL_QUERY ;
25+
2026/**
2127 * @property \chillerlan\OAuth\Core\OAuth2Interface $provider
2228 */
@@ -46,19 +52,19 @@ public function testOAuth2Instance(){
4652
4753 public function testGetAuthURL (){
4854 $ url = $ this ->provider ->getAuthURL (['client_secret ' => 'foo ' ], ['some_scope ' ]);
49- \ parse_str (\ parse_url ($ url , \ PHP_URL_QUERY ), $ query );
55+ parse_str (parse_url ($ url , PHP_URL_QUERY ), $ query );
5056
5157 $ this ->assertArrayNotHasKey ('client_secret ' , $ query );
5258 $ this ->assertSame ($ this ->options ->key , $ query ['client_id ' ]);
5359 $ this ->assertSame ('code ' , $ query ['response_type ' ]);
54- $ this ->assertSame (\ explode ('? ' , $ url )[0 ], $ this ->getProperty ('authURL ' )->getValue ($ this ->provider ));
60+ $ this ->assertSame (explode ('? ' , $ url )[0 ], $ this ->getProperty ('authURL ' )->getValue ($ this ->provider ));
5561 }
5662
5763 public function testGetAccessToken (){
5864 $ token = $ this ->provider ->getAccessToken ('foo ' , 'test_state ' );
5965
6066 $ this ->assertSame ('test_access_token ' , $ token ->accessToken );
61- $ this ->assertGreaterThan (\ time (), $ token ->expires );
67+ $ this ->assertGreaterThan (time (), $ token ->expires );
6268 }
6369
6470 public function testParseTokenResponseNoDataException (){
@@ -67,7 +73,7 @@ public function testParseTokenResponseNoDataException(){
6773
6874 $ this
6975 ->getMethod ('parseTokenResponse ' )
70- ->invokeArgs ($ this ->provider , [(new Response )->withBody (Psr17 \ create_stream_from_input ('' ))])
76+ ->invokeArgs ($ this ->provider , [(new Response )->withBody (create_stream_from_input ('' ))])
7177 ;
7278 }
7379
@@ -77,7 +83,7 @@ public function testParseTokenResponseErrorException(){
7783
7884 $ this
7985 ->getMethod ('parseTokenResponse ' )
80- ->invokeArgs ($ this ->provider , [(new Response )->withBody (Psr17 \ create_stream_from_input ('{"error":"whatever"} ' ))])
86+ ->invokeArgs ($ this ->provider , [(new Response )->withBody (create_stream_from_input ('{"error":"whatever"} ' ))])
8187 ;
8288 }
8389
@@ -87,7 +93,7 @@ public function testParseTokenResponseNoTokenException(){
8793
8894 $ this
8995 ->getMethod ('parseTokenResponse ' )
90- ->invokeArgs ($ this ->provider , [(new Response )->withBody (Psr17 \ create_stream_from_input ('{"foo":"bar"} ' ))])
96+ ->invokeArgs ($ this ->provider , [(new Response )->withBody (create_stream_from_input ('{"foo":"bar"} ' ))])
9197 ;
9298 }
9399
@@ -99,11 +105,17 @@ public function testGetRequestAuthorization(){
99105
100106 // header (default)
101107 if (isset (OAuth2Interface::AUTH_METHODS_HEADER [$ authMethod ])){
102- $ this ->assertStringContainsString (OAuth2Interface::AUTH_METHODS_HEADER [$ authMethod ].'test_token ' , $ this ->provider ->getRequestAuthorization ($ request , $ token )->getHeaderLine ('Authorization ' ));
108+ $ this ->assertStringContainsString (
109+ OAuth2Interface::AUTH_METHODS_HEADER [$ authMethod ].'test_token ' ,
110+ $ this ->provider ->getRequestAuthorization ($ request , $ token )->getHeaderLine ('Authorization ' )
111+ );
103112 }
104113 // query
105114 elseif (isset (OAuth2Interface::AUTH_METHODS_QUERY [$ authMethod ])){
106- $ this ->assertStringContainsString (OAuth2Interface::AUTH_METHODS_QUERY [$ authMethod ].'=test_token ' , $ this ->provider ->getRequestAuthorization ($ request , $ token )->getUri ()->getQuery ());
115+ $ this ->assertStringContainsString (
116+ OAuth2Interface::AUTH_METHODS_QUERY [$ authMethod ].'=test_token ' ,
117+ $ this ->provider ->getRequestAuthorization ($ request , $ token )->getUri ()->getQuery ()
118+ );
107119 }
108120
109121 }
@@ -112,7 +124,7 @@ public function testRequest(){
112124 $ token = new AccessToken (['accessToken ' => 'test_access_token_secret ' , 'expires ' => 1 ]);
113125 $ this ->storage ->storeAccessToken ($ this ->provider ->serviceName , $ token );
114126
115- $ this ->assertSame ('such data! much wow! ' , Psr7 \ get_json ($ this ->provider ->request ('/request ' ))->data );
127+ $ this ->assertSame ('such data! much wow! ' , get_json ($ this ->provider ->request ('/request ' ))->data );
116128 }
117129
118130 public function testRequestInvalidAuthTypeException (){
@@ -198,7 +210,7 @@ public function testRefreshAccessToken(){
198210
199211 $ this ->assertSame ('test_refresh_token ' , $ token ->refreshToken );
200212 $ this ->assertSame ('test_refreshed_access_token ' , $ token ->accessToken );
201- $ this ->assertGreaterThan (\ time (), $ token ->expires );
213+ $ this ->assertGreaterThan (time (), $ token ->expires );
202214 }
203215
204216 public function testRequestWithTokenRefresh (){
@@ -211,9 +223,9 @@ public function testRequestWithTokenRefresh(){
211223 $ token = new AccessToken (['accessToken ' => 'test_access_token ' , 'refreshToken ' => 'test_refresh_token ' , 'expires ' => 1 ]);
212224 $ this ->storage ->storeAccessToken ($ this ->provider ->serviceName , $ token );
213225
214- \ sleep (2 );
226+ sleep (2 );
215227
216- $ this ->assertSame ('such data! much wow! ' , Psr7 \ get_json ($ this ->provider ->request ('/request ' ))->data );
228+ $ this ->assertSame ('such data! much wow! ' , get_json ($ this ->provider ->request ('/request ' ))->data );
217229 }
218230
219231 public function testGetClientCredentials (){
@@ -226,7 +238,7 @@ public function testGetClientCredentials(){
226238 $ token = $ this ->provider ->getClientCredentialsToken (['some_scope ' ]);
227239
228240 $ this ->assertSame ('test_client_credentials_token ' , $ token ->accessToken );
229- $ this ->assertGreaterThan (\ time (), $ token ->expires );
241+ $ this ->assertGreaterThan (time (), $ token ->expires );
230242 }
231243
232244}
0 commit comments