Skip to content

Commit a177902

Browse files
committed
mark classes as final and methods and properties as private
1 parent 14a2a39 commit a177902

25 files changed

+451
-406
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
### Changed
66
- Abstract method `HttpClientPool::chooseHttpClient()` has now an explicit return type (`Http\Client\Common\HttpClientPoolItem`)
77
- Interface method `Plugin::handleRequest(...)` has now an explicit return type (`Http\Promise\Promise`)
8+
- Made all classes final as they are not intended to be extended.
9+
Added interfaces for BatchClient, HttpClientPool, HttpClientRouter and HttpMethodsClient.
10+
Those classes have been renamed with an `Impl` suffix.
811

912
### Removed
1013
- Deprecated option `debug_plugins` has been removed from `PluginClient`

spec/BatchClientSpec.php renamed to spec/BatchClientImplSpec.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
use Psr\Http\Message\RequestInterface;
77
use Psr\Http\Message\ResponseInterface;
88
use PhpSpec\ObjectBehavior;
9-
use Http\Client\Common\BatchClient;
9+
use Http\Client\Common\BatchClientImpl;
1010
use Http\Client\Common\BatchResult;
1111
use Http\Client\Exception\HttpException;
1212
use Http\Client\Common\Exception\BatchException;
1313

14-
class BatchClientSpec extends ObjectBehavior
14+
class BatchClientImplSpec extends ObjectBehavior
1515
{
1616
public function let(HttpClient $client)
1717
{
18-
$this->beAnInstanceOf(BatchClient::class, [$client]);
18+
$this->beAnInstanceOf(BatchClientImpl::class, [$client]);
1919
}
2020

2121
public function it_send_multiple_request_using_send_request(HttpClient $client, RequestInterface $request1, RequestInterface $request2, ResponseInterface $response1, ResponseInterface $response2)

spec/HttpClientPoolItemSpec.php renamed to spec/HttpClientPool/HttpClientPoolItemImplSpec.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace spec\Http\Client\Common;
3+
namespace spec\Http\Client\Common\HttpClientPool;
44

55
use Http\Client\Exception;
66
use Http\Client\Exception\TransferException;
@@ -14,7 +14,7 @@
1414
use Psr\Http\Message\ResponseInterface;
1515
use Http\Client\Exception\RequestException;
1616

17-
class HttpClientPoolItemSpec extends ObjectBehavior
17+
class HttpClientPoolItemImplSpec extends ObjectBehavior
1818
{
1919
public function let(HttpClient $httpClient)
2020
{

spec/HttpClientPool/LeastUsedClientPoolSpec.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
namespace spec\Http\Client\Common\HttpClientPool;
44

5-
use Http\Client\Common\HttpClientPoolItem;
5+
use Http\Client\Common\HttpClientPool\HttpClientPoolItem;
6+
use Http\Client\Common\HttpClientPool\HttpClientPoolItemImpl;
67
use Http\Client\HttpAsyncClient;
78
use Http\Client\HttpClient;
89
use Http\Promise\Promise;
@@ -65,7 +66,7 @@ public function it_throw_exception_if_no_more_enable_client(HttpClient $client,
6566

6667
public function it_reenable_client(HttpClient $client, RequestInterface $request)
6768
{
68-
$this->addHttpClient(new HttpClientPoolItem($client->getWrappedObject(), 0));
69+
$this->addHttpClient(new HttpClientPoolItemImpl($client->getWrappedObject(), 0));
6970
$client->sendRequest($request)->willThrow(HttpException::class);
7071

7172
$this->shouldThrow(HttpException::class)->duringSendRequest($request);

spec/HttpClientPool/RandomClientPoolSpec.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace spec\Http\Client\Common\HttpClientPool;
44

5-
use Http\Client\Common\HttpClientPoolItem;
5+
use Http\Client\Common\HttpClientPool\HttpClientPoolItemImpl;
66
use Http\Client\HttpAsyncClient;
77
use Http\Client\HttpClient;
88
use Http\Promise\Promise;
@@ -65,7 +65,7 @@ public function it_throw_exception_if_no_more_enable_client(HttpClient $client,
6565

6666
public function it_reenable_client(HttpClient $client, RequestInterface $request)
6767
{
68-
$this->addHttpClient(new HttpClientPoolItem($client->getWrappedObject(), 0));
68+
$this->addHttpClient(new HttpClientPoolItemImpl($client->getWrappedObject(), 0));
6969
$client->sendRequest($request)->willThrow(HttpException::class);
7070

7171
$this->shouldThrow(HttpException::class)->duringSendRequest($request);

spec/HttpClientPool/RoundRobinClientPoolSpec.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace spec\Http\Client\Common\HttpClientPool;
44

5-
use Http\Client\Common\HttpClientPoolItem;
5+
use Http\Client\Common\HttpClientPool\HttpClientPoolItemImpl;
66
use Http\Client\HttpAsyncClient;
77
use Http\Client\HttpClient;
88
use Http\Promise\Promise;
@@ -65,7 +65,7 @@ public function it_throw_exception_if_no_more_enable_client(HttpClient $client,
6565

6666
public function it_reenable_client(HttpClient $client, RequestInterface $request)
6767
{
68-
$this->addHttpClient(new HttpClientPoolItem($client->getWrappedObject(), 0));
68+
$this->addHttpClient(new HttpClientPoolItemImpl($client->getWrappedObject(), 0));
6969
$client->sendRequest($request)->willThrow(HttpException::class);
7070

7171
$this->shouldThrow(HttpException::class)->duringSendRequest($request);

spec/HttpClientRouterSpec.php renamed to spec/HttpClientRouterImplSpec.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace spec\Http\Client\Common;
44

5+
use Http\Client\Common\HttpClientRouterImpl;
56
use Http\Message\RequestMatcher;
67
use Http\Client\HttpAsyncClient;
78
use Http\Client\HttpClient;
@@ -12,11 +13,16 @@
1213
use Http\Client\Common\HttpClientRouter;
1314
use Http\Client\Exception\RequestException;
1415

15-
class HttpClientRouterSpec extends ObjectBehavior
16+
class HttpClientRouterImplSpec extends ObjectBehavior
1617
{
1718
public function it_is_initializable()
1819
{
19-
$this->shouldHaveType(HttpClientRouter::class);
20+
$this->shouldHaveType(HttpClientRouterImpl::class);
21+
}
22+
23+
public function it_is_an_http_client_router()
24+
{
25+
$this->shouldImplement(HttpClientRouter::class);
2026
}
2127

2228
public function it_is_an_http_client()

spec/HttpMethodsClientImplSpec.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
namespace spec\Http\Client\Common;
4+
5+
use Http\Client\Common\HttpMethodsClientImpl;
6+
use Http\Client\HttpClient;
7+
use Http\Message\RequestFactory;
8+
use PhpSpec\ObjectBehavior;
9+
use Psr\Http\Message\RequestInterface;
10+
use Psr\Http\Message\ResponseInterface;
11+
12+
class HttpMethodsClientImplSpec extends ObjectBehavior
13+
{
14+
private static $requestData = [
15+
'uri' => '/uri',
16+
'headers' => [
17+
'Content-Type' => 'text/plain',
18+
],
19+
'body' => 'body',
20+
];
21+
22+
public function let(HttpClient $client, RequestFactory $requestFactory)
23+
{
24+
$this->beAnInstanceOf(
25+
HttpMethodsClientImpl::class, [
26+
$client,
27+
$requestFactory,
28+
]
29+
);
30+
}
31+
32+
public function it_sends_a_get_request(HttpClient $client, RequestFactory $requestFactory, RequestInterface $request, ResponseInterface $response)
33+
{
34+
$this->assert($client, $requestFactory, $request, $response, 'get');
35+
}
36+
37+
public function it_sends_a_head_request(HttpClient $client, RequestFactory $requestFactory, RequestInterface $request, ResponseInterface $response)
38+
{
39+
$this->assert($client, $requestFactory, $request, $response, 'head');
40+
}
41+
42+
public function it_sends_a_trace_request(HttpClient $client, RequestFactory $requestFactory, RequestInterface $request, ResponseInterface $response)
43+
{
44+
$this->assert($client, $requestFactory, $request, $response, 'trace');
45+
}
46+
47+
public function it_sends_a_post_request(HttpClient $client, RequestFactory $requestFactory, RequestInterface $request, ResponseInterface $response)
48+
{
49+
$this->assert($client, $requestFactory, $request, $response, 'post', self::$requestData['body']);
50+
}
51+
52+
public function it_sends_a_put_request(HttpClient $client, RequestFactory $requestFactory, RequestInterface $request, ResponseInterface $response)
53+
{
54+
$this->assert($client, $requestFactory, $request, $response, 'put', self::$requestData['body']);
55+
}
56+
57+
public function it_sends_a_patch_request(HttpClient $client, RequestFactory $requestFactory, RequestInterface $request, ResponseInterface $response)
58+
{
59+
$this->assert($client, $requestFactory, $request, $response, 'patch', self::$requestData['body']);
60+
}
61+
62+
public function it_sends_a_delete_request(HttpClient $client, RequestFactory $requestFactory, RequestInterface $request, ResponseInterface $response)
63+
{
64+
$this->assert($client, $requestFactory, $request, $response, 'delete', self::$requestData['body']);
65+
}
66+
67+
public function it_sends_an_options_request(HttpClient $client, RequestFactory $requestFactory, RequestInterface $request, ResponseInterface $response)
68+
{
69+
$this->assert($client, $requestFactory, $request, $response, 'options', self::$requestData['body']);
70+
}
71+
72+
/**
73+
* Run the actual test.
74+
*
75+
* As there is no data provider in phpspec, we keep separate methods to get new mocks for each test.
76+
*/
77+
private function assert(HttpClient $client, RequestFactory $requestFactory, RequestInterface $request, ResponseInterface $response, string $method, string $body = null)
78+
{
79+
$client->sendRequest($request)->shouldBeCalled()->willReturn($response);
80+
$this->mockFactory($requestFactory, $request, strtoupper($method), $body);
81+
82+
$this->$method(self::$requestData['uri'], self::$requestData['headers'], self::$requestData['body'])->shouldReturnAnInstanceOf(ResponseInterface::class);
83+
}
84+
85+
private function mockFactory(RequestFactory $requestFactory, RequestInterface $request, string $method, string $body = null)
86+
{
87+
$requestFactory->createRequest($method, self::$requestData['uri'], self::$requestData['headers'], $body)->willReturn($request);
88+
}
89+
}

spec/HttpMethodsClientSpec.php

Lines changed: 0 additions & 136 deletions
This file was deleted.

0 commit comments

Comments
 (0)