Conditions | 1 |
Paths | 1 |
Total Lines | 76 |
Code Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
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 |
||
44 | public function testGetAuthenticatedRequest() |
||
45 | { |
||
46 | // Clear the cache to make sure we get fresh results during testing. |
||
47 | $cache = new FilesystemAdapter('acquia-php-sdk-v2'); |
||
48 | $cache->deleteItem('cloudapi-token'); |
||
49 | |||
50 | $config = [ |
||
51 | 'key' => 'key', |
||
52 | 'secret' => 'secret' |
||
53 | ]; |
||
54 | |||
55 | // Create a new Connector and override the provider property set in the constructor. |
||
56 | $connector = new Connector($config); |
||
57 | $reflectionClass = new \ReflectionClass('AcquiaCloudApi\Connector\Connector'); |
||
58 | |||
59 | $provider = new MockProvider([ |
||
60 | 'clientId' => 'mock_client_id', |
||
61 | 'clientSecret' => 'mock_secret', |
||
62 | 'redirectUri' => 'none', |
||
63 | ]); |
||
64 | |||
65 | $providerProperty = $reflectionClass->getProperty('provider'); |
||
66 | $providerProperty->setAccessible(true); |
||
67 | $providerProperty->setValue($connector, $provider); |
||
68 | |||
69 | // Create the mock response from the call to get the access token. |
||
70 | $expires = time() + 300; |
||
71 | $raw_response = ['access_token' => 'acquia-token', 'expires' => $expires, 'resource_owner_id' => 3]; |
||
72 | |||
73 | $grant = Phony::mock(AbstractGrant::class); |
||
74 | $grant->prepareRequestParameters->returns([]); |
||
75 | |||
76 | $stream = Phony::mock(StreamInterface::class); |
||
77 | $stream->__toString->returns(json_encode($raw_response)); |
||
78 | |||
79 | $response = Phony::mock(ResponseInterface::class); |
||
80 | $response->getBody->returns($stream->get()); |
||
81 | $response->getHeader->with('content-type')->returns('application/json'); |
||
82 | |||
83 | $client = Phony::mock(ClientInterface::class); |
||
84 | $client->send->returns($response->get()); |
||
85 | |||
86 | $provider->setHttpClient($client->get()); |
||
87 | |||
88 | // Create the request and check it matches our expectations. |
||
89 | $request = $connector->createRequest('get', '/account'); |
||
90 | $this->assertInstanceOf('GuzzleHttp\Psr7\Request', $request); |
||
91 | |||
92 | $expectedHeaders = [ |
||
93 | 'Host' => [ |
||
94 | 'cloud.acquia.com', |
||
95 | ], |
||
96 | 'Authorization' => [ |
||
97 | 'Bearer acquia-token', |
||
98 | ] |
||
99 | ]; |
||
100 | $expectedHeaderNames = [ |
||
101 | 'authorization' => 'Authorization', |
||
102 | 'host' => 'Host', |
||
103 | ]; |
||
104 | |||
105 | $this->assertAttributeSame($expectedHeaders, 'headers', $request); |
||
106 | $this->assertAttributeSame($expectedHeaderNames, 'headerNames', $request); |
||
107 | |||
108 | // Check the cache to make sure that the token has been cached successfully. |
||
109 | $accessToken = $cache->getItem('cloudapi-token')->get(); |
||
110 | |||
111 | // Ensure that the cached item is an AccessToken and that it contains the values we set above. |
||
112 | $this->assertInstanceOf('League\OAuth2\Client\Token\AccessToken', $accessToken); |
||
113 | $this->assertAttributeSame('acquia-token', 'accessToken', $accessToken); |
||
114 | $this->assertAttributeSame(3, 'resourceOwnerId', $accessToken); |
||
115 | $this->assertAttributeSame($expires, 'expires', $accessToken); |
||
116 | |||
117 | // Delete the cached token again to clean up. |
||
118 | $delete = $cache->deleteItem('cloudapi-token'); |
||
119 | $this->assertTrue($delete); |
||
120 | } |
||
165 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths