Skip to content

Commit e87785c

Browse files
committed
Use ::class anywhere
1 parent 2a80705 commit e87785c

32 files changed

+226
-152
lines changed

spec/BatchClientSpec.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,31 @@
66
use Psr\Http\Message\RequestInterface;
77
use Psr\Http\Message\ResponseInterface;
88
use PhpSpec\ObjectBehavior;
9+
use Http\Client\Common\BatchClient;
10+
use Http\Client\Common\BatchResult;
11+
use Http\Client\Exception\HttpException;
12+
use Http\Client\Common\Exception\BatchException;
913

1014
class BatchClientSpec extends ObjectBehavior
1115
{
1216
function let(HttpClient $client)
1317
{
14-
$this->beAnInstanceOf('Http\Client\Common\BatchClient', [$client]);
18+
$this->beAnInstanceOf(BatchClient::class, [$client]);
1519
}
1620

1721
function it_send_multiple_request_using_send_request(HttpClient $client, RequestInterface $request1, RequestInterface $request2, ResponseInterface $response1, ResponseInterface $response2)
1822
{
1923
$client->sendRequest($request1)->willReturn($response1);
2024
$client->sendRequest($request2)->willReturn($response2);
2125

22-
$this->sendRequests([$request1, $request2])->shouldReturnAnInstanceOf('Http\Client\Common\BatchResult');
26+
$this->sendRequests([$request1, $request2])->shouldReturnAnInstanceOf(BatchResult::class);
2327
}
2428

2529
function it_throw_batch_exception_if_one_or_more_request_failed(HttpClient $client, RequestInterface $request1, RequestInterface $request2, ResponseInterface $response)
2630
{
2731
$client->sendRequest($request1)->willReturn($response);
28-
$client->sendRequest($request2)->willThrow('Http\Client\Exception\HttpException');
32+
$client->sendRequest($request2)->willThrow(HttpException::class);
2933

30-
$this->shouldThrow('Http\Client\Common\Exception\BatchException')->duringSendRequests([$request1, $request2]);
34+
$this->shouldThrow(BatchException::class)->duringSendRequests([$request1, $request2]);
3135
}
3236
}

spec/BatchResultSpec.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@
66
use Psr\Http\Message\RequestInterface;
77
use Psr\Http\Message\ResponseInterface;
88
use PhpSpec\ObjectBehavior;
9+
use Http\Client\Common\BatchResult;
910

1011
class BatchResultSpec extends ObjectBehavior
1112
{
1213
function it_is_initializable()
1314
{
14-
$this->beAnInstanceOf('Http\Client\Common\BatchResult');
15+
$this->beAnInstanceOf(BatchResult::class);
1516
}
1617

1718
function it_is_immutable(RequestInterface $request, ResponseInterface $response)
1819
{
1920
$new = $this->addResponse($request, $response);
2021

2122
$this->getResponses()->shouldReturn([]);
22-
$new->shouldHaveType('Http\Client\Common\BatchResult');
23+
$new->shouldHaveType(BatchResult::class);
2324
$new->getResponses()->shouldReturn([$response]);
2425
}
2526

@@ -37,7 +38,7 @@ function it_has_a_response_for_a_request(RequestInterface $request, ResponseInte
3738
{
3839
$new = $this->addResponse($request, $response);
3940

40-
$this->shouldThrow('UnexpectedValueException')->duringGetResponseFor($request);
41+
$this->shouldThrow(\UnexpectedValueException::class)->duringGetResponseFor($request);
4142
$this->isSuccessful($request)->shouldReturn(false);
4243
$new->getResponseFor($request)->shouldReturn($response);
4344
$new->isSuccessful($request)->shouldReturn(true);

spec/EmulatedHttpAsyncClientSpec.php

+11-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
use Psr\Http\Message\RequestInterface;
77
use Psr\Http\Message\ResponseInterface;
88
use PhpSpec\ObjectBehavior;
9+
use Http\Client\Common\EmulatedHttpAsyncClient;
10+
use Http\Client\HttpAsyncClient;
11+
use Http\Client\Promise\HttpFulfilledPromise;
12+
use Http\Client\Exception\TransferException;
13+
use Http\Client\Promise\HttpRejectedPromise;
914

1015
class EmulatedHttpAsyncClientSpec extends ObjectBehavior
1116
{
@@ -16,17 +21,17 @@ function let(HttpClient $httpClient)
1621

1722
function it_is_initializable()
1823
{
19-
$this->shouldHaveType('Http\Client\Common\EmulatedHttpAsyncClient');
24+
$this->shouldHaveType(EmulatedHttpAsyncClient::class);
2025
}
2126

2227
function it_is_an_http_client()
2328
{
24-
$this->shouldImplement('Http\Client\HttpClient');
29+
$this->shouldImplement(HttpClient::class);
2530
}
2631

2732
function it_is_an_async_http_client()
2833
{
29-
$this->shouldImplement('Http\Client\HttpAsyncClient');
34+
$this->shouldImplement(HttpAsyncClient::class);
3035
}
3136

3237
function it_emulates_a_successful_request(
@@ -36,14 +41,14 @@ function it_emulates_a_successful_request(
3641
) {
3742
$httpClient->sendRequest($request)->willReturn($response);
3843

39-
$this->sendAsyncRequest($request)->shouldReturnAnInstanceOf('Http\Client\Promise\HttpFulfilledPromise');
44+
$this->sendAsyncRequest($request)->shouldReturnAnInstanceOf(HttpFulfilledPromise::class);
4045
}
4146

4247
function it_emulates_a_failed_request(HttpClient $httpClient, RequestInterface $request)
4348
{
44-
$httpClient->sendRequest($request)->willThrow('Http\Client\Exception\TransferException');
49+
$httpClient->sendRequest($request)->willThrow(TransferException::class);
4550

46-
$this->sendAsyncRequest($request)->shouldReturnAnInstanceOf('Http\Client\Promise\HttpRejectedPromise');
51+
$this->sendAsyncRequest($request)->shouldReturnAnInstanceOf(HttpRejectedPromise::class);
4752
}
4853

4954
function it_decorates_the_underlying_client(

spec/EmulatedHttpClientSpec.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Psr\Http\Message\RequestInterface;
1010
use Psr\Http\Message\ResponseInterface;
1111
use PhpSpec\ObjectBehavior;
12+
use Http\Client\Common\EmulatedHttpClient;
13+
use Http\Client\Exception;
1214

1315
class EmulatedHttpClientSpec extends ObjectBehavior
1416
{
@@ -19,17 +21,17 @@ function let(HttpAsyncClient $httpAsyncClient)
1921

2022
function it_is_initializable()
2123
{
22-
$this->shouldHaveType('Http\Client\Common\EmulatedHttpClient');
24+
$this->shouldHaveType(EmulatedHttpClient::class);
2325
}
2426

2527
function it_is_an_http_client()
2628
{
27-
$this->shouldImplement('Http\Client\HttpClient');
29+
$this->shouldImplement(HttpClient::class);
2830
}
2931

3032
function it_is_an_async_http_client()
3133
{
32-
$this->shouldImplement('Http\Client\HttpAsyncClient');
34+
$this->shouldImplement(HttpAsyncClient::class);
3335
}
3436

3537
function it_emulates_a_successful_request(
@@ -55,7 +57,7 @@ function it_emulates_a_failed_request(HttpAsyncClient $httpAsyncClient, RequestI
5557

5658
$httpAsyncClient->sendAsyncRequest($request)->willReturn($promise);
5759

58-
$this->shouldThrow('Http\Client\Exception')->duringSendRequest($request);
60+
$this->shouldThrow(Exception::class)->duringSendRequest($request);
5961
}
6062

6163
function it_decorates_the_underlying_client(

spec/Exception/BatchExceptionSpec.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Http\Client\Common\BatchResult;
66
use Http\Client\Exception;
77
use PhpSpec\ObjectBehavior;
8+
use Http\Client\Common\Exception\BatchException;
89

910
class BatchExceptionSpec extends ObjectBehavior
1011
{
@@ -16,21 +17,21 @@ function let()
1617

1718
function it_is_initializable()
1819
{
19-
$this->shouldHaveType('Http\Client\Common\Exception\BatchException');
20+
$this->shouldHaveType(BatchException::class);
2021
}
2122

2223
function it_is_a_runtime_exception()
2324
{
24-
$this->shouldHaveType('RuntimeException');
25+
$this->shouldHaveType(\RuntimeException::class);
2526
}
2627

2728
function it_is_an_exception()
2829
{
29-
$this->shouldImplement('Http\Client\Exception');
30+
$this->shouldImplement(Exception::class);
3031
}
3132

3233
function it_has_a_batch_result()
3334
{
34-
$this->getResult()->shouldHaveType('Http\Client\Common\BatchResult');
35+
$this->getResult()->shouldHaveType(BatchResult::class);
3536
}
3637
}

spec/FlexibleHttpClientSpec.php

+8-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Psr\Http\Message\RequestInterface;
99
use Psr\Http\Message\ResponseInterface;
1010
use PhpSpec\ObjectBehavior;
11+
use Http\Client\Common\FlexibleHttpClient;
1112

1213
class FlexibleHttpClientSpec extends ObjectBehavior
1314
{
@@ -18,24 +19,24 @@ function let(HttpClient $httpClient)
1819

1920
function it_is_initializable()
2021
{
21-
$this->shouldHaveType('Http\Client\Common\FlexibleHttpClient');
22+
$this->shouldHaveType(FlexibleHttpClient::class);
2223
}
2324

2425
function it_is_an_http_client()
2526
{
26-
$this->shouldImplement('Http\Client\HttpClient');
27+
$this->shouldImplement(HttpClient::class);
2728
}
2829

2930
function it_is_an_async_http_client()
3031
{
31-
$this->shouldImplement('Http\Client\HttpAsyncClient');
32+
$this->shouldImplement(HttpAsyncClient::class);
3233
}
3334

3435
function it_throw_exception_if_invalid_client()
3536
{
3637
$this->beConstructedWith(null);
3738

38-
$this->shouldThrow('\LogicException')->duringInstantiation();
39+
$this->shouldThrow(\LogicException::class)->duringInstantiation();
3940
}
4041

4142
function it_emulates_an_async_client(
@@ -53,7 +54,7 @@ function it_emulates_an_async_client(
5354
$this->sendRequest($syncRequest)->shouldReturn($syncResponse);
5455
$promise = $this->sendAsyncRequest($asyncRequest);
5556

56-
$promise->shouldHaveType('Http\Promise\Promise');
57+
$promise->shouldHaveType(Promise::class);
5758
$promise->wait()->shouldReturn($asyncResponse);
5859
}
5960

@@ -77,8 +78,8 @@ function it_emulates_a_client(
7778

7879
function it_does_not_emulate_a_client($client, RequestInterface $syncRequest, RequestInterface $asyncRequest)
7980
{
80-
$client->implement('Http\Client\HttpClient');
81-
$client->implement('Http\Client\HttpAsyncClient');
81+
$client->implement(HttpClient::class);
82+
$client->implement(HttpAsyncClient::class);
8283

8384
$client->sendRequest($syncRequest)->shouldBeCalled();
8485
$client->sendRequest($asyncRequest)->shouldNotBeCalled();

spec/HttpClientPool/LeastUsedClientPoolSpec.php

+14-11
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,31 @@
1111
use Prophecy\Argument;
1212
use Psr\Http\Message\RequestInterface;
1313
use Psr\Http\Message\ResponseInterface;
14+
use Http\Client\Common\HttpClientPool\LeastUsedClientPool;
15+
use Http\Client\Common\Exception\HttpClientNotFoundException;
16+
use Http\Client\Exception\HttpException;
1417

1518
class LeastUsedClientPoolSpec extends ObjectBehavior
1619
{
1720
public function it_is_initializable()
1821
{
19-
$this->shouldHaveType('Http\Client\Common\HttpClientPool\LeastUsedClientPool');
22+
$this->shouldHaveType(LeastUsedClientPool::class);
2023
}
2124

2225
public function it_is_an_http_client()
2326
{
24-
$this->shouldImplement('Http\Client\HttpClient');
27+
$this->shouldImplement(HttpClient::class);
2528
}
2629

2730
public function it_is_an_async_http_client()
2831
{
29-
$this->shouldImplement('Http\Client\HttpAsyncClient');
32+
$this->shouldImplement(HttpAsyncClient::class);
3033
}
3134

3235
public function it_throw_exception_with_no_client(RequestInterface $request)
3336
{
34-
$this->shouldThrow('Http\Client\Common\Exception\HttpClientNotFoundException')->duringSendRequest($request);
35-
$this->shouldThrow('Http\Client\Common\Exception\HttpClientNotFoundException')->duringSendAsyncRequest($request);
37+
$this->shouldThrow(HttpClientNotFoundException::class)->duringSendRequest($request);
38+
$this->shouldThrow(HttpClientNotFoundException::class)->duringSendAsyncRequest($request);
3639
}
3740

3841
public function it_sends_request(HttpClient $httpClient, RequestInterface $request, ResponseInterface $response)
@@ -55,19 +58,19 @@ public function it_sends_async_request(HttpAsyncClient $httpAsyncClient, Request
5558
public function it_throw_exception_if_no_more_enable_client(HttpClient $client, RequestInterface $request)
5659
{
5760
$this->addHttpClient($client);
58-
$client->sendRequest($request)->willThrow('Http\Client\Exception\HttpException');
61+
$client->sendRequest($request)->willThrow(HttpException::class);
5962

60-
$this->shouldThrow('Http\Client\Exception\HttpException')->duringSendRequest($request);
61-
$this->shouldThrow('Http\Client\Common\Exception\HttpClientNotFoundException')->duringSendRequest($request);
63+
$this->shouldThrow(HttpException::class)->duringSendRequest($request);
64+
$this->shouldThrow(HttpClientNotFoundException::class)->duringSendRequest($request);
6265
}
6366

6467
public function it_reenable_client(HttpClient $client, RequestInterface $request)
6568
{
6669
$this->addHttpClient(new HttpClientPoolItem($client->getWrappedObject(), 0));
67-
$client->sendRequest($request)->willThrow('Http\Client\Exception\HttpException');
70+
$client->sendRequest($request)->willThrow(HttpException::class);
6871

69-
$this->shouldThrow('Http\Client\Exception\HttpException')->duringSendRequest($request);
70-
$this->shouldThrow('Http\Client\Exception\HttpException')->duringSendRequest($request);
72+
$this->shouldThrow(HttpException::class)->duringSendRequest($request);
73+
$this->shouldThrow(HttpException::class)->duringSendRequest($request);
7174
}
7275

7376
public function it_uses_the_lowest_request_client(HttpClientPoolItem $client1, HttpClientPoolItem $client2, RequestInterface $request, ResponseInterface $response)

spec/HttpClientPool/RandomClientPoolSpec.php

+14-11
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,31 @@
1010
use Prophecy\Argument;
1111
use Psr\Http\Message\RequestInterface;
1212
use Psr\Http\Message\ResponseInterface;
13+
use Http\Client\Common\HttpClientPool\RandomClientPool;
14+
use Http\Client\Common\Exception\HttpClientNotFoundException;
15+
use Http\Client\Exception\HttpException;
1316

1417
class RandomClientPoolSpec extends ObjectBehavior
1518
{
1619
public function it_is_initializable()
1720
{
18-
$this->shouldHaveType('Http\Client\Common\HttpClientPool\RandomClientPool');
21+
$this->shouldHaveType(RandomClientPool::class);
1922
}
2023

2124
public function it_is_an_http_client()
2225
{
23-
$this->shouldImplement('Http\Client\HttpClient');
26+
$this->shouldImplement(HttpClient::class);
2427
}
2528

2629
public function it_is_an_async_http_client()
2730
{
28-
$this->shouldImplement('Http\Client\HttpAsyncClient');
31+
$this->shouldImplement(HttpAsyncClient::class);
2932
}
3033

3134
public function it_throw_exception_with_no_client(RequestInterface $request)
3235
{
33-
$this->shouldThrow('Http\Client\Common\Exception\HttpClientNotFoundException')->duringSendRequest($request);
34-
$this->shouldThrow('Http\Client\Common\Exception\HttpClientNotFoundException')->duringSendAsyncRequest($request);
36+
$this->shouldThrow(HttpClientNotFoundException::class)->duringSendRequest($request);
37+
$this->shouldThrow(HttpClientNotFoundException::class)->duringSendAsyncRequest($request);
3538
}
3639

3740
public function it_sends_request(HttpClient $httpClient, RequestInterface $request, ResponseInterface $response)
@@ -54,18 +57,18 @@ public function it_sends_async_request(HttpAsyncClient $httpAsyncClient, Request
5457
public function it_throw_exception_if_no_more_enable_client(HttpClient $client, RequestInterface $request)
5558
{
5659
$this->addHttpClient($client);
57-
$client->sendRequest($request)->willThrow('Http\Client\Exception\HttpException');
60+
$client->sendRequest($request)->willThrow(HttpException::class);
5861

59-
$this->shouldThrow('Http\Client\Exception\HttpException')->duringSendRequest($request);
60-
$this->shouldThrow('Http\Client\Common\Exception\HttpClientNotFoundException')->duringSendRequest($request);
62+
$this->shouldThrow(HttpException::class)->duringSendRequest($request);
63+
$this->shouldThrow(HttpClientNotFoundException::class)->duringSendRequest($request);
6164
}
6265

6366
public function it_reenable_client(HttpClient $client, RequestInterface $request)
6467
{
6568
$this->addHttpClient(new HttpClientPoolItem($client->getWrappedObject(), 0));
66-
$client->sendRequest($request)->willThrow('Http\Client\Exception\HttpException');
69+
$client->sendRequest($request)->willThrow(HttpException::class);
6770

68-
$this->shouldThrow('Http\Client\Exception\HttpException')->duringSendRequest($request);
69-
$this->shouldThrow('Http\Client\Exception\HttpException')->duringSendRequest($request);
71+
$this->shouldThrow(HttpException::class)->duringSendRequest($request);
72+
$this->shouldThrow(HttpException::class)->duringSendRequest($request);
7073
}
7174
}

0 commit comments

Comments
 (0)