Skip to content

Commit fd42060

Browse files
authored
Merge pull request #66 from php-http/cleanup-major
changes for version 4
2 parents 4edf2ac + e690a19 commit fd42060

File tree

9 files changed

+143
-209
lines changed

9 files changed

+143
-209
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@ jobs:
1515
max-parallel: 10
1616
matrix:
1717
batch:
18-
- { suite: "curl", php: '7.4', package: "php-http/curl-client laminas/laminas-diactoros php-http/message-factory" }
18+
- { suite: "curl", php: '8.1', package: "php-http/curl-client laminas/laminas-diactoros php-http/message-factory" }
1919
- { suite: "curl", php: '8.5', package: "php-http/curl-client laminas/laminas-diactoros php-http/message-factory" }
20-
- { suite: "Socket", php: '7.4', package: "php-http/socket-client php-http/client-common php-http/message-factory" }
20+
- { suite: "Socket", php: '8.1', package: "php-http/socket-client php-http/client-common php-http/message-factory" }
2121
- { suite: "Socket", php: '8.5', package: "php-http/socket-client php-http/client-common php-http/message-factory" }
2222
- { suite: "Guzzle", php: '7.4', package: "guzzlehttp/guzzle php-http/message-factory" }
2323
- { suite: "Guzzle", php: '8.5', package: "guzzlehttp/guzzle php-http/message-factory" }
2424
- { suite: "Guzzle", php: '7.4', package: "guzzlehttp/guzzle phpunit/phpunit:^8.5.8 php-http/message-factory" }
2525
- { suite: "Guzzle", php: '7.4', package: "guzzlehttp/guzzle phpunit/phpunit:^7.5.20 php-http/message-factory" }
26-
- { suite: "Buzz", php: '7.4', package: "kriswallsmith/buzz psr/log php-http/message-factory" }
2726
- { suite: "Buzz", php: '8.5', package: "kriswallsmith/buzz psr/log php-http/message-factory" }
2827

2928
steps:

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ All notable changes to this project will be documented in this file.
66
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

9+
# 4.x
10+
11+
- Allow PHPUnit > 9
12+
- Removed deprecated PhpUnitBackwardCompatibleTrait
13+
- Replaced deprecated HttpBaseTest::$messageFactory with $requestFactory and $streamFactory
14+
- Parameter type and return type declarations on all test classes
15+
916
# 3.x
1017

1118
## [3.1.3] - 2025-12-08

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
],
1717
"require": {
1818
"php": "^7.4 || ^8.0",
19+
"ext-json": "*",
1920
"phpunit/phpunit": "^9.6.17 || ^10.0 || ^11.0 || ^12.0",
2021
"php-http/message": "^1.0 || ^2.0",
21-
"php-http/message-factory": "^1.0",
2222
"guzzlehttp/psr7": "^1.9 || ^2.0",
2323
"th3n3rd/cartesian-product": "^0.3"
2424
},
@@ -27,7 +27,7 @@
2727
},
2828
"require-dev": {
2929
"php-http/httplug": "^2.0",
30-
"nyholm/psr7": "^1.8@dev"
30+
"nyholm/psr7": "^1.8"
3131
},
3232
"autoload": {
3333
"psr-4": {

src/HttpAsyncClientTest.php

Lines changed: 45 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,44 @@
22

33
namespace Http\Client\Tests;
44

5+
use Http\Client\Exception;
56
use Http\Client\HttpAsyncClient;
7+
use Http\Promise\Promise;
68
use PHPUnit\Framework\Attributes\DataProvider;
79
use PHPUnit\Framework\Attributes\Group;
810

911
abstract class HttpAsyncClientTest extends HttpBaseTest
1012
{
11-
/**
12-
* @var HttpAsyncClient
13-
*/
14-
protected $httpAsyncClient;
13+
protected HttpAsyncClient $httpAsyncClient;
1514

16-
/**
17-
* {@inheritdoc}
18-
*/
1915
protected function setUp(): void
2016
{
2117
$this->httpAsyncClient = $this->createHttpAsyncClient();
2218
}
2319

24-
/**
25-
* {@inheritdoc}
26-
*/
2720
protected function tearDown(): void
2821
{
2922
unset($this->httpAdapter);
3023
}
3124

3225
abstract protected function createHttpAsyncClient(): HttpAsyncClient;
3326

34-
public function testSuccessiveCallMustUseResponseInterface()
27+
public function testSuccessiveCallMustUseResponseInterface(): void
3528
{
36-
$request = self::$messageFactory->createRequest(
37-
'GET',
38-
$this->getUri(),
39-
$this->defaultHeaders
40-
);
29+
$request = self::$requestFactory->createRequest('GET', self::getUri());
30+
foreach (self::$defaultHeaders as $name => $value) {
31+
$request = $request->withHeader($name, $value);
32+
}
33+
4134

4235
$promise = $this->httpAsyncClient->sendAsyncRequest($request);
43-
$this->assertInstanceOf('Http\Promise\Promise', $promise);
36+
$this->assertInstanceOf(Promise::class, $promise);
4437

4538
$response = null;
4639
$promise->then()->then()->then(function ($r) use (&$response) {
4740
$response = $r;
4841

49-
return $response;
42+
return $r;
5043
});
5144

5245
$promise->wait(false);
@@ -58,23 +51,22 @@ public function testSuccessiveCallMustUseResponseInterface()
5851
);
5952
}
6053

61-
public function testSuccessiveInvalidCallMustUseException()
54+
public function testSuccessiveInvalidCallMustUseException(): void
6255
{
63-
$request = self::$messageFactory->createRequest(
64-
'GET',
65-
$this->getInvalidUri(),
66-
$this->defaultHeaders
67-
);
56+
$request = self::$requestFactory->createRequest('GET', $this->getInvalidUri());
57+
foreach (self::$defaultHeaders as $name => $value) {
58+
$request = $request->withHeader($name, $value);
59+
}
6860

6961
$promise = $this->httpAsyncClient->sendAsyncRequest($request);
70-
$this->assertInstanceOf('Http\Promise\Promise', $promise);
62+
$this->assertInstanceOf(Promise::class, $promise);
7163

7264
$exception = null;
7365
$response = null;
7466
$promise->then()->then()->then(function ($r) use (&$response) {
7567
$response = $r;
7668

77-
return $response;
69+
return $r;
7870
}, function ($e) use (&$exception) {
7971
$exception = $e;
8072

@@ -85,7 +77,7 @@ public function testSuccessiveInvalidCallMustUseException()
8577

8678
$this->assertNull($response);
8779
$this->assertNotNull($exception);
88-
$this->assertInstanceOf('\Http\Client\Exception', $exception);
80+
$this->assertInstanceOf(Exception::class, $exception);
8981
}
9082

9183
/**
@@ -94,21 +86,22 @@ public function testSuccessiveInvalidCallMustUseException()
9486
*/
9587
#[DataProvider('requestProvider')]
9688
#[Group('integration')]
97-
public function testAsyncSendRequest($method, $uri, array $headers, $body)
89+
public function testAsyncSendRequest(string $method, string $uri, array $headers, ?string $body): void
9890
{
9991
if (null != $body) {
10092
$headers['Content-Length'] = (string) strlen($body);
10193
}
10294

103-
$request = self::$messageFactory->createRequest(
104-
$method,
105-
$uri,
106-
$headers,
107-
$body
108-
);
95+
$request = self::$requestFactory->createRequest($method, $uri);
96+
foreach ($headers as $name => $value) {
97+
$request = $request->withHeader($name, $value);
98+
}
99+
if (null !== $body) {
100+
$request = $request->withBody(self::$streamFactory->createStream($body));
101+
}
109102

110103
$promise = $this->httpAsyncClient->sendAsyncRequest($request);
111-
$this->assertInstanceOf('Http\Promise\Promise', $promise);
104+
$this->assertInstanceOf(Promise::class, $promise);
112105

113106
$response = null;
114107
$promise->then(function ($r) use (&$response) {
@@ -131,18 +124,17 @@ public function testAsyncSendRequest($method, $uri, array $headers, $body)
131124
* @group integration
132125
*/
133126
#[Group('integration')]
134-
public function testSendAsyncWithInvalidUri()
127+
public function testSendAsyncWithInvalidUri(): void
135128
{
136-
$request = self::$messageFactory->createRequest(
137-
'GET',
138-
$this->getInvalidUri(),
139-
$this->defaultHeaders
140-
);
129+
$request = self::$requestFactory->createRequest('GET', $this->getInvalidUri());
130+
foreach (self::$defaultHeaders as $name => $value) {
131+
$request = $request->withHeader($name, $value);
132+
}
141133

142134
$exception = null;
143135
$response = null;
144136
$promise = $this->httpAsyncClient->sendAsyncRequest($request);
145-
$this->assertInstanceOf('Http\Promise\Promise', $promise);
137+
$this->assertInstanceOf(Promise::class, $promise);
146138

147139
$promise->then(function ($r) use (&$response) {
148140
$response = $r;
@@ -157,7 +149,7 @@ public function testSendAsyncWithInvalidUri()
157149

158150
$this->assertNull($response);
159151
$this->assertNotNull($exception);
160-
$this->assertInstanceOf('\Http\Client\Exception', $exception);
152+
$this->assertInstanceOf(Exception::class, $exception);
161153
}
162154

163155
/**
@@ -166,7 +158,7 @@ public function testSendAsyncWithInvalidUri()
166158
*/
167159
#[Group('integration')]
168160
#[DataProvider('requestWithOutcomeProvider')]
169-
public function testSendAsyncRequestWithOutcome($uriAndOutcome, $protocolVersion, array $headers, $body)
161+
public function testSendAsyncRequestWithOutcome(array $uriAndOutcome, string $protocolVersion, array $headers, ?string $body): void
170162
{
171163
if ('1.0' === $protocolVersion) {
172164
$body = null;
@@ -176,13 +168,14 @@ public function testSendAsyncRequestWithOutcome($uriAndOutcome, $protocolVersion
176168
$headers['Content-Length'] = (string) strlen($body);
177169
}
178170

179-
$request = self::$messageFactory->createRequest(
180-
$method = 'GET',
181-
$uriAndOutcome[0],
182-
$headers,
183-
$body,
184-
$protocolVersion
185-
);
171+
$request = self::$requestFactory->createRequest($method = 'GET', $uriAndOutcome[0]);
172+
foreach ($headers as $name => $value) {
173+
$request = $request->withHeader($name, $value);
174+
}
175+
if (null !== $body) {
176+
$request = $request->withBody(self::$streamFactory->createStream($body));
177+
}
178+
$request = $request->withProtocolVersion($protocolVersion);
186179

187180
$outcome = $uriAndOutcome[1];
188181
$outcome['protocolVersion'] = $protocolVersion;
@@ -195,7 +188,7 @@ public function testSendAsyncRequestWithOutcome($uriAndOutcome, $protocolVersion
195188
return $response;
196189
});
197190

198-
$this->assertInstanceOf('Http\Promise\Promise', $promise);
191+
$this->assertInstanceOf(Promise::class, $promise);
199192
$promise->wait();
200193
$this->assertResponse(
201194
$response,

0 commit comments

Comments
 (0)