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