@@ -117,28 +117,42 @@ public function testUserData()
117
117
$ this ->assertEquals ($ location , $ user ->toArray ()['location ' ]);
118
118
}
119
119
120
- /**
121
- *
122
- * @expectedException \League\OAuth2\Client\Provider\Exception\IdentityProviderException
123
- */
124
120
public function testUserDataFails ()
125
121
{
126
- $ postResponse = m::mock ('Psr\Http\Message\ResponseInterface ' );
127
- $ postResponse ->shouldReceive ('getBody ' )->andReturn ('{"access_token": "mock_access_token","scopes": "account","expires_in": 3600,"refresh_token": "mock_refresh_token","token_type": "bearer"} ' );
128
- $ postResponse ->shouldReceive ('getHeader ' )->andReturn (['content-type ' => 'json ' ]);
129
-
130
- $ userResponse = m::mock ('Psr\Http\Message\ResponseInterface ' );
131
- $ userResponse ->shouldReceive ('getBody ' )->andReturn ('{"error":"mock_error","error_description": "mock_error_description"} ' );
132
- $ userResponse ->shouldReceive ('getHeader ' )->andReturn (['content-type ' => 'json ' ]);
133
- $ userResponse ->shouldReceive ('getStatusCode ' )->andReturn (500 );
134
-
135
- $ client = m::mock ('GuzzleHttp\ClientInterface ' );
136
- $ client ->shouldReceive ('send ' )
137
- ->times (2 )
138
- ->andReturn ($ postResponse , $ userResponse );
139
- $ this ->provider ->setHttpClient ($ client );
140
-
141
- $ token = $ this ->provider ->getAccessToken ('authorization_code ' , ['code ' => 'mock_authorization_code ' ]);
142
- $ user = $ this ->provider ->getResourceOwner ($ token );
122
+ $ errorPayloads = [
123
+ '{"error":"mock_error","error_description": "mock_error_description"} ' ,
124
+ '{"error":{"message":"mock_error"},"error_description": "mock_error_description"} ' ,
125
+ '{"foo":"bar"} '
126
+ ];
127
+
128
+ $ testPayload = function ($ payload ) {
129
+ $ postResponse = m::mock ('Psr\Http\Message\ResponseInterface ' );
130
+ $ postResponse ->shouldReceive ('getBody ' )->andReturn ('{"access_token": "mock_access_token","scopes": "account","expires_in": 3600,"refresh_token": "mock_refresh_token","token_type": "bearer"} ' );
131
+ $ postResponse ->shouldReceive ('getHeader ' )->andReturn (['content-type ' => 'json ' ]);
132
+
133
+ $ userResponse = m::mock ('Psr\Http\Message\ResponseInterface ' );
134
+ $ userResponse ->shouldReceive ('getBody ' )->andReturn ($ payload );
135
+ $ userResponse ->shouldReceive ('getHeader ' )->andReturn (['content-type ' => 'json ' ]);
136
+ $ userResponse ->shouldReceive ('getStatusCode ' )->andReturn (500 );
137
+
138
+ $ client = m::mock ('GuzzleHttp\ClientInterface ' );
139
+ $ client ->shouldReceive ('send ' )
140
+ ->times (2 )
141
+ ->andReturn ($ postResponse , $ userResponse );
142
+ $ this ->provider ->setHttpClient ($ client );
143
+
144
+ $ token = $ this ->provider ->getAccessToken ('authorization_code ' , ['code ' => 'mock_authorization_code ' ]);
145
+
146
+ try {
147
+ $ user = $ this ->provider ->getResourceOwner ($ token );
148
+ return false ;
149
+ } catch (\Exception $ e ) {
150
+ $ this ->assertInstanceOf ('\League\OAuth2\Client\Provider\Exception\IdentityProviderException ' , $ e );
151
+ }
152
+
153
+ return $ payload ;
154
+ };
155
+
156
+ $ this ->assertCount (2 , array_filter (array_map ($ testPayload , $ errorPayloads )));
143
157
}
144
158
}
0 commit comments