1212
1313namespace chillerlan \OAuthTest \Providers ;
1414
15- use chillerlan \HTTP \Psr7 \{Request , Response };
1615use chillerlan \HTTP \Psr17 ;
17- use chillerlan \OAuth \Core \{AccessToken , AccessTokenForRefresh , ClientCredentials , CSRFToken , OAuth2Interface , TokenRefresh };
16+ use chillerlan \HTTP \Psr7 \{Request , Response };
17+ use chillerlan \OAuth \Core \{AccessToken , AccessTokenForRefresh , ClientCredentials , CSRFToken , OAuth2Interface , ProviderException , TokenRefresh };
18+ use chillerlan \OAuth \OAuthException ;
1819
1920/**
2021 * @property \chillerlan\OAuth\Core\OAuth2Interface $provider
@@ -43,7 +44,7 @@ abstract class OAuth2ProviderTestAbstract extends ProviderTestAbstract{
4344 '/oauth2/api/request/test/get ' => ['foo ' ],
4445 ];
4546
46- protected function setUp (){
47+ protected function setUp (): void {
4748 parent ::setUp ();
4849
4950 $ this ->setProperty ($ this ->provider , 'apiURL ' , 'https://localhost/oauth2/api/request ' );
@@ -84,33 +85,30 @@ public function testGetAccessToken(){
8485 $ this ->assertGreaterThan (time (), $ token ->expires );
8586 }
8687
87- /**
88- * @expectedException \chillerlan\OAuth\Core\ProviderException
89- * @expectedExceptionMessage unable to parse token response
90- */
91- public function testParseTokenResponseNoData (){
88+ public function testParseTokenResponseNoDataException (){
89+ $ this ->expectException (ProviderException::class);
90+ $ this ->expectExceptionMessage ('unable to parse token response ' );
91+
9292 $ this
9393 ->getMethod ('parseTokenResponse ' )
9494 ->invokeArgs ($ this ->provider , [(new Response )->withBody (Psr17 \create_stream_from_input ('' ))])
9595 ;
9696 }
9797
98- /**
99- * @expectedException \chillerlan\OAuth\Core\ProviderException
100- * @expectedExceptionMessage error retrieving access token
101- */
102- public function testParseTokenResponseError (){
98+ public function testParseTokenResponseErrorException (){
99+ $ this ->expectException (ProviderException::class);
100+ $ this ->expectExceptionMessage ('error retrieving access token ' );
101+
103102 $ this
104103 ->getMethod ('parseTokenResponse ' )
105104 ->invokeArgs ($ this ->provider , [(new Response )->withBody (Psr17 \create_stream_from_input ('{"error":"whatever"} ' ))])
106105 ;
107106 }
108107
109- /**
110- * @expectedException \chillerlan\OAuth\Core\ProviderException
111- * @expectedExceptionMessage token missing
112- */
113- public function testParseTokenResponseNoToken (){
108+ public function testParseTokenResponseNoTokenException (){
109+ $ this ->expectException (ProviderException::class);
110+ $ this ->expectExceptionMessage ('token missing ' );
111+
114112 $ this
115113 ->getMethod ('parseTokenResponse ' )
116114 ->invokeArgs ($ this ->provider , [(new Response )->withBody (Psr17 \create_stream_from_input ('{"foo":"bar"} ' ))])
@@ -125,11 +123,11 @@ public function testGetRequestAuthorization(){
125123
126124 // header (default)
127125 if (isset (OAuth2Interface::AUTH_METHODS_HEADER [$ authMethod ])){
128- $ this ->assertContains (OAuth2Interface::AUTH_METHODS_HEADER [$ authMethod ].'test_token ' , $ this ->provider ->getRequestAuthorization ($ request , $ token )->getHeaderLine ('Authorization ' ));
126+ $ this ->assertStringContainsString (OAuth2Interface::AUTH_METHODS_HEADER [$ authMethod ].'test_token ' , $ this ->provider ->getRequestAuthorization ($ request , $ token )->getHeaderLine ('Authorization ' ));
129127 }
130128 // query
131129 elseif (isset (OAuth2Interface::AUTH_METHODS_QUERY [$ authMethod ])){
132- $ this ->assertContains (OAuth2Interface::AUTH_METHODS_QUERY [$ authMethod ].'=test_token ' , $ this ->provider ->getRequestAuthorization ($ request , $ token )->getUri ()->getQuery ());
130+ $ this ->assertStringContainsString (OAuth2Interface::AUTH_METHODS_QUERY [$ authMethod ].'=test_token ' , $ this ->provider ->getRequestAuthorization ($ request , $ token )->getUri ()->getQuery ());
133131 }
134132
135133 }
@@ -141,11 +139,10 @@ public function testRequest(){
141139 $ this ->assertSame ('such data! much wow! ' , json_decode ($ this ->provider ->request ('' )->getBody ()->getContents ())->data );
142140 }
143141
144- /**
145- * @expectedException \chillerlan\OAuth\OAuthException
146- * @expectedExceptionMessage invalid auth type
147- */
148- public function testRequestInvalidAuthType (){
142+ public function testRequestInvalidAuthTypeException (){
143+ $ this ->expectException (OAuthException::class);
144+ $ this ->expectExceptionMessage ('invalid auth type ' );
145+
149146 $ this ->setProperty ($ this ->provider , 'authMethod ' , 'foo ' );
150147 $ token = new AccessToken (['accessToken ' => 'test_access_token_secret ' , 'expires ' => 1 ]);
151148 $ this ->storage ->storeAccessToken ($ this ->provider ->serviceName , $ token );
@@ -168,11 +165,9 @@ public function testCheckCSRFState(){
168165 $ this ->expectNotToPerformAssertions ();
169166 }
170167
171- /**
172- * @expectedException \chillerlan\OAuth\Core\ProviderException
173- * @expectedExceptionMessage invalid state
174- */
175- public function testCheckStateInvalid (){
168+ public function testCheckStateInvalidException (){
169+ $ this ->expectException (ProviderException::class);
170+ $ this ->expectExceptionMessage ('invalid state ' );
176171
177172 if (!$ this ->provider instanceof CSRFToken){
178173 $ this ->markTestSkipped ('CSRFToken N/A ' );
@@ -184,11 +179,9 @@ public function testCheckStateInvalid(){
184179 ->invoke ($ this ->provider );
185180 }
186181
187- /**
188- * @expectedException \chillerlan\OAuth\Core\ProviderException
189- * @expectedExceptionMessage invalid CSRF state
190- */
191- public function testCheckStateInvalidCSRFState (){
182+ public function testCheckStateInvalidCSRFStateException (){
183+ $ this ->expectException (ProviderException::class);
184+ $ this ->expectExceptionMessage ('invalid CSRF state ' );
192185
193186 if (!$ this ->provider instanceof CSRFToken){
194187 $ this ->markTestSkipped ('CSRFToken N/A ' );
@@ -200,11 +193,9 @@ public function testCheckStateInvalidCSRFState(){
200193 ->invokeArgs ($ this ->provider , ['invalid_test_state ' ]);
201194 }
202195
203- /**
204- * @expectedException \chillerlan\OAuth\OAuthException
205- * @expectedExceptionMessage no refresh token available, token expired [
206- */
207196 public function testRefreshAccessTokenNoRefreshTokenAvailable (){
197+ $ this ->expectException (OAuthException::class);
198+ $ this ->expectExceptionMessage ('no refresh token available, token expired [ ' );
208199
209200 if (!$ this ->provider instanceof TokenRefresh){
210201 $ this ->markTestSkipped ('TokenRefresh N/A ' );
0 commit comments