Skip to content

Commit 48bfe2d

Browse files
authored
Merge pull request #43 from php-http/feature/psr18-only
3.x preparation : Make httplug optional, depends on psr18
2 parents c320718 + 032a731 commit 48bfe2d

File tree

7 files changed

+34
-78
lines changed

7 files changed

+34
-78
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
77
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88

99

10-
## [Unreleased]
10+
## [3.0.0] - Unreleased
11+
12+
- Only support HTTPlug 2.0 and PSR-18
13+
- HTTPlug 2.0 is now optional (only require it if you need to test async)
14+
- HttpClientTest now relies only on PSR-18 (no need for HTTPlug)
1115

1216
## [2.0.1] - 2018-12-27
1317

composer.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@
1515
}
1616
],
1717
"require": {
18-
"php": ">=5.4",
19-
"phpunit/phpunit": "^4.8.35 || ^5.4.3 || ^6.0 || ^7.0",
20-
"php-http/httplug": "^1.0 || ^2.0",
18+
"php": "^7.1",
19+
"phpunit/phpunit": "^7.0",
2120
"php-http/message": "^1.0",
2221
"guzzlehttp/psr7": "^1.0",
2322
"th3n3rd/cartesian-product": "^0.3"
2423
},
24+
"suggest": {
25+
"php-http/httplug": "To test async client"
26+
},
27+
"require-dev": {
28+
"php-http/httplug": "^2.0"
29+
},
2530
"autoload": {
2631
"psr-4": {
2732
"Http\\Client\\Tests\\": "src/"
@@ -44,7 +49,7 @@
4449
],
4550
"extra": {
4651
"branch-alias": {
47-
"dev-master": "2.x-dev"
52+
"dev-master": "3.x-dev"
4853
}
4954
}
5055
}

src/HttpAsyncClientTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ protected function tearDown()
2727
unset($this->httpAdapter);
2828
}
2929

30-
/**
31-
* @return HttpAsyncClient
32-
*/
33-
abstract protected function createHttpAsyncClient();
30+
abstract protected function createHttpAsyncClient(): HttpAsyncClient;
3431

3532
public function testSuccessiveCallMustUseResponseInterface()
3633
{

src/HttpBaseTest.php

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@ public static function tearDownAfterClass()
5959
}
6060
}
6161

62-
/**
63-
* @return array
64-
*/
65-
public function requestProvider()
62+
public function requestProvider(): array
6663
{
6764
$sets = [
6865
'methods' => $this->getMethods(),
@@ -85,10 +82,7 @@ public function requestProvider()
8582
});
8683
}
8784

88-
/**
89-
* @return array
90-
*/
91-
public function requestWithOutcomeProvider()
85+
public function requestWithOutcomeProvider(): array
9286
{
9387
$sets = [
9488
'urisAndOutcomes' => $this->getUrisAndOutcomes(),
@@ -102,10 +96,7 @@ public function requestWithOutcomeProvider()
10296
return $cartesianProduct->compute();
10397
}
10498

105-
/**
106-
* @return array
107-
*/
108-
private function getMethods()
99+
private function getMethods(): array
109100
{
110101
return [
111102
'GET',
@@ -211,14 +202,8 @@ private function getData()
211202
return ['param1' => 'foo', 'param2' => ['bar', ['baz']]];
212203
}
213204

214-
/**
215-
* @param ResponseInterface $response
216-
* @param array $options
217-
*/
218-
protected function assertResponse($response, array $options = [])
205+
protected function assertResponse(ResponseInterface $response, array $options = [])
219206
{
220-
$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response);
221-
222207
$options = array_merge($this->defaultOptions, $options);
223208

224209
// The response version may be greater or equal to the request version. See https://tools.ietf.org/html/rfc2145#section-2.3

src/HttpClientTest.php

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

33
namespace Http\Client\Tests;
44

5-
use Http\Client\HttpClient;
5+
use Psr\Http\Client\ClientInterface;
66

77
/**
88
* @author GeLo <[email protected]>
99
*/
1010
abstract class HttpClientTest extends HttpBaseTest
1111
{
1212
/**
13-
* @var HttpClient
13+
* @var ClientInterface
1414
*/
1515
protected $httpAdapter;
1616

@@ -30,10 +30,7 @@ protected function tearDown()
3030
unset($this->httpAdapter);
3131
}
3232

33-
/**
34-
* @return HttpClient
35-
*/
36-
abstract protected function createHttpAdapter();
33+
abstract protected function createHttpAdapter(): ClientInterface;
3734

3835
/**
3936
* @dataProvider requestProvider

src/HttpFeatureTest.php

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

33
namespace Http\Client\Tests;
44

5-
use Http\Client\HttpClient;
5+
use Psr\Http\Client\ClientInterface;
66
use Http\Message\MessageFactory;
77
use Http\Message\MessageFactory\GuzzleMessageFactory;
88
use PHPUnit\Framework\TestCase;
@@ -22,10 +22,7 @@ public static function setUpBeforeClass()
2222
self::$messageFactory = new GuzzleMessageFactory();
2323
}
2424

25-
/**
26-
* @return HttpClient
27-
*/
28-
abstract protected function createClient();
25+
abstract protected function createClient(): ClientInterface;
2926

3027
/**
3128
* @feature Send a GET Request
@@ -39,7 +36,6 @@ public function testGet()
3936

4037
$response = $this->createClient()->sendRequest($request);
4138

42-
$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response);
4339
$this->assertSame(200, $response->getStatusCode());
4440
}
4541

@@ -58,7 +54,6 @@ public function testPost()
5854

5955
$response = $this->createClient()->sendRequest($request);
6056

61-
$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response);
6257
$this->assertSame(200, $response->getStatusCode());
6358

6459
$contents = json_decode($response->getBody()->__toString());
@@ -78,7 +73,6 @@ public function testPatch()
7873

7974
$response = $this->createClient()->sendRequest($request);
8075

81-
$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response);
8276
$this->assertSame(200, $response->getStatusCode());
8377
}
8478

@@ -94,7 +88,6 @@ public function testPut()
9488

9589
$response = $this->createClient()->sendRequest($request);
9690

97-
$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response);
9891
$this->assertSame(200, $response->getStatusCode());
9992
}
10093

@@ -110,7 +103,6 @@ public function testDelete()
110103

111104
$response = $this->createClient()->sendRequest($request);
112105

113-
$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response);
114106
$this->assertSame(200, $response->getStatusCode());
115107
}
116108

@@ -129,7 +121,6 @@ public function testAutoSetContentLength()
129121

130122
$response = $this->createClient()->sendRequest($request);
131123

132-
$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response);
133124
$this->assertSame(200, $response->getStatusCode());
134125

135126
$contents = json_decode($response->getBody()->__toString());
@@ -149,7 +140,6 @@ public function testEncoding()
149140

150141
$response = $this->createClient()->sendRequest($request);
151142

152-
$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response);
153143
$this->assertSame(200, $response->getStatusCode());
154144
$this->assertContains('', $response->getBody()->__toString());
155145
}
@@ -166,7 +156,6 @@ public function testGzip()
166156

167157
$response = $this->createClient()->sendRequest($request);
168158

169-
$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response);
170159
$this->assertSame(200, $response->getStatusCode());
171160
$this->assertContains('gzip', $response->getBody()->__toString());
172161
}
@@ -183,7 +172,6 @@ public function testDeflate()
183172

184173
$response = $this->createClient()->sendRequest($request);
185174

186-
$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response);
187175
$this->assertSame(200, $response->getStatusCode());
188176
$this->assertContains('deflate', $response->getBody()->__toString());
189177
}
@@ -200,7 +188,6 @@ public function testRedirect()
200188

201189
$response = $this->createClient()->sendRequest($request);
202190

203-
$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response);
204191
$this->assertSame(200, $response->getStatusCode());
205192
}
206193

@@ -216,7 +203,6 @@ public function testChunked()
216203

217204
$response = $this->createClient()->sendRequest($request);
218205

219-
$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response);
220206
$this->assertSame(200, $response->getStatusCode());
221207

222208
$content = @json_decode($response->getBody()->__toString());
@@ -236,7 +222,6 @@ public function testSsl()
236222

237223
$response = $this->createClient()->sendRequest($request);
238224

239-
$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response);
240225
$this->assertSame(200, $response->getStatusCode());
241226
}
242227
}

src/ResultPrinter.php

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,19 @@
33
namespace Http\Client\Tests;
44

55
use PHPUnit\Framework\Test;
6+
use PHPUnit\TextUI\ResultPrinter as BaseResultPrinter;
67

7-
// If PHPUnit 6
8-
if (class_exists('\\PHPUnit\\TextUI\\ResultPrinter')) {
9-
class ResultPrinter extends \PHPUnit\TextUI\ResultPrinter
10-
{
11-
use FeatureTestListener;
12-
13-
public function startTest(Test $test)
14-
{
15-
return $this->doStartTest($test);
16-
}
8+
class ResultPrinter extends BaseResultPrinter
9+
{
10+
use FeatureTestListener;
1711

18-
public function endTest(Test $test, $time)
19-
{
20-
return $this->doEndTest($test, $time);
21-
}
22-
}
23-
} else {
24-
class ResultPrinter extends \PHPUnit_TextUI_ResultPrinter
12+
public function startTest(Test $test): void
2513
{
26-
use FeatureTestListener;
27-
28-
public function startTest(\PHPUnit_Framework_Test $test)
29-
{
30-
return $this->doStartTest($test);
31-
}
14+
return $this->doStartTest($test);
15+
}
3216

33-
public function endTest(\PHPUnit_Framework_Test $test, $time)
34-
{
35-
return $this->doEndTest($test, $time);
36-
}
17+
public function endTest(Test $test, float $time): void
18+
{
19+
return $this->doEndTest($test, $time);
3720
}
3821
}

0 commit comments

Comments
 (0)