1111
1212namespace chillerlan \OAuthTest \Providers \Unit ;
1313
14- use chillerlan \OAuth \Core \{AccessToken , OAuth1Interface };
14+ use chillerlan \OAuth \Core \{AccessToken , OAuth1Interface , UnauthorizedAccessException };
1515use chillerlan \HTTP \Utils \MessageUtil ;
1616use chillerlan \OAuth \Providers \ProviderException ;
1717use function str_starts_with ;
@@ -78,11 +78,8 @@ public function testSendRequestTokenRequest():void{
7878 */
7979
8080 public function testParseAccessTokenResponse ():void {
81-
82- $ response = $ this ->responseFactory
83- ->createResponse ()
84- ->withBody ($ this ->streamFactory ->createStream ($ this ::TEST_ACCESS_TOKEN ))
85- ;
81+ $ body = $ this ->streamFactory ->createStream ($ this ::TEST_ACCESS_TOKEN );
82+ $ response = $ this ->responseFactory ->createResponse ()->withBody ($ body );
8683
8784 /** @var \chillerlan\OAuth\Core\AccessToken $token */
8885 $ token = $ this ->invokeReflectionMethod ('parseTokenResponse ' , [$ response ]);
@@ -92,11 +89,8 @@ public function testParseAccessTokenResponse():void{
9289 }
9390
9491 public function testParseTemporaryCredentialsTokenResponse ():void {
95-
96- $ response = $ this ->responseFactory
97- ->createResponse ()
98- ->withBody ($ this ->streamFactory ->createStream ($ this ::TEST_REQUEST_TOKEN ))
99- ;
92+ $ body = $ this ->streamFactory ->createStream ($ this ::TEST_REQUEST_TOKEN );
93+ $ response = $ this ->responseFactory ->createResponse ()->withBody ($ body );
10094
10195 /** @var \chillerlan\OAuth\Core\AccessToken $token */
10296 $ token = $ this ->invokeReflectionMethod ('parseTokenResponse ' , [$ response , true ]);
@@ -122,6 +116,16 @@ public function testParseTokenResponseErrorException():void{
122116 $ this ->invokeReflectionMethod ('parseTokenResponse ' , [$ response ]);
123117 }
124118
119+ public function testParseTokenResponseUnauthorizedException ():void {
120+ $ this ->expectException (UnauthorizedAccessException::class);
121+ $ this ->expectExceptionMessage ('Unauthorized ' );
122+
123+ $ body = $ this ->streamFactory ->createStream ('error=Unauthorized ' );
124+ $ response = $ this ->responseFactory ->createResponse (401 )->withBody ($ body );
125+
126+ $ this ->invokeReflectionMethod ('parseTokenResponse ' , [$ response ]);
127+ }
128+
125129 public function testParseTokenResponseNoTokenException ():void {
126130 $ this ->expectException (ProviderException::class);
127131 $ this ->expectExceptionMessage ('invalid token ' );
@@ -150,7 +154,7 @@ public function testParseTokenResponseConfirmCallbackException():void{
150154 public function testGetAccessToken ():void {
151155 $ this ->setMockResponse ($ this ->streamFactory ->createStream ($ this ::TEST_ACCESS_TOKEN ));
152156
153- $ requestToken = new AccessToken ([
157+ $ requestToken = $ this -> getTestToken ([
154158 'accessToken ' => 'hdk48Djdsa ' ,
155159 'accessTokenSecret ' => 'xyz4992k83j47x0b ' ,
156160 'expires ' => AccessToken::NEVER_EXPIRES ,
@@ -165,7 +169,7 @@ public function testGetAccessToken():void{
165169
166170 public function testSendAccessTokenRequest ():void {
167171 // we need the request token for the access token request
168- $ requestToken = new AccessToken ([
172+ $ requestToken = $ this -> getTestToken ([
169173 'accessToken ' => 'hdk48Djdsa ' ,
170174 'accessTokenSecret ' => 'xyz4992k83j47x0b ' ,
171175 'expires ' => AccessToken::NEVER_EXPIRES ,
@@ -190,11 +194,12 @@ public function testGetAccessTokenRequestTokenMismatchException():void{
190194 $ this ->expectException (ProviderException::class);
191195 $ this ->expectExceptionMessage ('request token mismatch ' );
192196
193- $ requestToken = new AccessToken (['accessToken ' => 'hdk48Djdsa ' ]);
197+ $ requestToken = $ this -> getTestToken (['accessToken ' => 'hdk48Djdsa ' ]);
194198
195- $ this ->provider ->storeAccessToken ($ requestToken );
196-
197- $ this ->provider ->getAccessToken ('nope ' , 'verifier ' );
199+ $ this ->provider
200+ ->storeAccessToken ($ requestToken )
201+ ->getAccessToken ('nope ' , 'verifier ' )
202+ ;
198203 }
199204
200205
@@ -204,7 +209,7 @@ public function testGetAccessTokenRequestTokenMismatchException():void{
204209
205210 public function testGetRequestAuthorization ():void {
206211 $ request = $ this ->requestFactory ->createRequest ('GET ' , 'https://foo.bar ' );
207- $ token = new AccessToken ([
212+ $ token = $ this -> getTestToken ([
208213 'accessTokenSecret ' => 'test_token_secret ' ,
209214 'accessToken ' => 'test_token ' ,
210215 'expires ' => AccessToken::NEVER_EXPIRES ,
0 commit comments