| Conditions | 2 |
| Paths | 2 |
| Total Lines | 78 |
| Code Lines | 63 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 171 | public function testProfileData(): void |
||
| 172 | { |
||
| 173 | try { |
||
| 174 | $userId = random_int(1000, 9999); |
||
| 175 | } catch (Exception $e) { |
||
| 176 | $userId = 999; |
||
| 177 | } |
||
| 178 | $username = uniqid('', true); |
||
| 179 | $email = uniqid('', true); |
||
| 180 | $mockString = 'mock_string_value'; |
||
| 181 | $mockInt = 123; |
||
| 182 | $mockArray = ['a' => 'A', 'b' => 'B', 'c' => 'C']; |
||
| 183 | |||
| 184 | $postResponse = m::mock('Psr\Http\Message\ResponseInterface'); |
||
| 185 | $postResponse->allows('getBody') |
||
| 186 | ->andReturns( |
||
| 187 | http_build_query([ |
||
| 188 | 'access_token' => 'mock_access_token', |
||
| 189 | 'expires_in' => 300, |
||
| 190 | 'refresh_expires_in' => 1800, |
||
| 191 | 'refresh_token' => 'mock_refresh_token', |
||
| 192 | 'token_type' => 'bearer', |
||
| 193 | 'not-before-policy' => 0, |
||
| 194 | 'scope' => 'profile' |
||
| 195 | ]) |
||
| 196 | ); |
||
| 197 | $postResponse->allows('getHeader') |
||
| 198 | ->andReturns(['content-type' => 'application/x-www-form-urlencoded']); |
||
| 199 | $postResponse->allows('getStatusCode') |
||
| 200 | ->andReturns(200); |
||
| 201 | |||
| 202 | $userResponse = m::mock('Psr\Http\Message\ResponseInterface'); |
||
| 203 | $userResponse->allows('getBody') |
||
| 204 | ->andReturns( |
||
| 205 | json_encode([ |
||
| 206 | '_id' => $userId, |
||
| 207 | 'username' => $username, |
||
| 208 | 'email' => $email, |
||
| 209 | 'mock_string' => $mockString, |
||
| 210 | 'mock_int' => $mockInt, |
||
| 211 | 'mock_array' => $mockArray, |
||
| 212 | ], JSON_THROW_ON_ERROR) |
||
| 213 | ); |
||
| 214 | $userResponse->allows('getHeader') |
||
| 215 | ->andReturns(['content-type' => 'json']); |
||
| 216 | $userResponse->allows('getStatusCode') |
||
| 217 | ->andReturns(200); |
||
| 218 | |||
| 219 | $client = m::mock('GuzzleHttp\ClientInterface'); |
||
| 220 | $client->expects('send') |
||
| 221 | ->times(2) |
||
| 222 | ->andReturns($postResponse, $userResponse); |
||
| 223 | /** @noinspection PhpParamsInspection */ |
||
| 224 | $this->provider->setHttpClient($client); |
||
| 225 | |||
| 226 | $token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']); |
||
| 227 | $profile = $this->provider->getResourceOwner($token); |
||
| 228 | |||
| 229 | $this->assertInstanceOf(ChasterAppResourceOwner::class, $profile); |
||
| 230 | $this->assertEquals($userId, $profile->getId()); |
||
| 231 | $this->assertEquals($userId, $profile->toArray()['_id']); |
||
| 232 | $this->assertEquals($userId, $profile->_id); |
||
| 233 | |||
| 234 | $this->assertEquals($username, $profile->getUsername()); |
||
| 235 | $this->assertEquals($username, $profile->toArray()['username']); |
||
| 236 | $this->assertEquals($username, $profile->username); |
||
| 237 | |||
| 238 | $this->assertEquals($email, $profile->getEmail()); |
||
| 239 | $this->assertEquals($email, $profile->toArray()['email']); |
||
| 240 | $this->assertEquals($email, $profile->email); |
||
| 241 | |||
| 242 | $this->assertEquals($mockString, $profile->toArray()['mock_string']); |
||
| 243 | $this->assertEquals($mockString, $profile->mock_string); |
||
| 244 | $this->assertEquals($mockInt, $profile->toArray()['mock_int']); |
||
| 245 | $this->assertEquals($mockInt, $profile->mock_int); |
||
| 246 | $this->assertEquals($mockArray, $profile->toArray()['mock_array']); |
||
| 247 | $this->assertEquals($mockArray, $profile->mock_array); |
||
| 248 | $this->assertNull($profile->mock_null); |
||
| 249 | } |
||
| 273 |