Skip to content

Commit 166a7e1

Browse files
authored
feat: allow PHPUnit 10-12 (#61)
1 parent d017e2a commit 166a7e1

File tree

9 files changed

+57
-38
lines changed

9 files changed

+57
-38
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
tools: composer:v2
3434

3535
- name: Checkout code
36-
uses: actions/checkout@v4
36+
uses: actions/checkout@v5
3737

3838
- name: Download dependencies
3939
run: |

.github/workflows/static.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
steps:
1515
- name: Checkout code
16-
uses: actions/checkout@v4
16+
uses: actions/checkout@v5
1717

1818
- name: PHP-CS-Fixer
1919
uses: docker://oskarstark/php-cs-fixer-ga:2.16.4

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ 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+
10+
## [3.1.2] - 2025-11-11
11+
12+
- Allow PHPUnit > 9
13+
- Deprecate PhpUnitBackwardCompatibleTrait
14+
915
## [3.1.1] - 2024-09-01
1016

1117
- Switched to `httpbin.org` for tests now that its fixed. (Reverts [#56](https://github.com/php-http/client-integration-tests/pull/56))

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
],
1717
"require": {
1818
"php": "^7.4 || ^8.0",
19-
"phpunit/phpunit": "^9.6.17",
19+
"phpunit/phpunit": "^9.6.17 || ^10.0 || ^11.0 || ^12.0",
2020
"php-http/message": "^1.0 || ^2.0",
2121
"php-http/message-factory": "^1.0",
2222
"guzzlehttp/psr7": "^1.9 || ^2.0",

src/HttpAsyncClientTest.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Http\Client\Tests;
44

55
use Http\Client\HttpAsyncClient;
6+
use PHPUnit\Framework\Attributes\DataProvider;
7+
use PHPUnit\Framework\Attributes\Group;
68

79
abstract class HttpAsyncClientTest extends HttpBaseTest
810
{
@@ -33,8 +35,8 @@ public function testSuccessiveCallMustUseResponseInterface()
3335
{
3436
$request = self::$messageFactory->createRequest(
3537
'GET',
36-
$this->getUri(),
37-
$this->defaultHeaders
38+
self::getUri(),
39+
self::$defaultHeaders
3840
);
3941

4042
$promise = $this->httpAsyncClient->sendAsyncRequest($request);
@@ -61,7 +63,7 @@ public function testSuccessiveInvalidCallMustUseException()
6163
$request = self::$messageFactory->createRequest(
6264
'GET',
6365
$this->getInvalidUri(),
64-
$this->defaultHeaders
66+
self::$defaultHeaders
6567
);
6668

6769
$promise = $this->httpAsyncClient->sendAsyncRequest($request);
@@ -90,6 +92,8 @@ public function testSuccessiveInvalidCallMustUseException()
9092
* @dataProvider requestProvider
9193
* @group integration
9294
*/
95+
#[DataProvider('requestProvider')]
96+
#[Group('integration')]
9397
public function testAsyncSendRequest($method, $uri, array $headers, $body)
9498
{
9599
if (null != $body) {
@@ -124,14 +128,15 @@ public function testAsyncSendRequest($method, $uri, array $headers, $body)
124128
}
125129

126130
/**
127-
* @group integration
131+
* @group integration
128132
*/
133+
#[Group('integration')]
129134
public function testSendAsyncWithInvalidUri()
130135
{
131136
$request = self::$messageFactory->createRequest(
132137
'GET',
133138
$this->getInvalidUri(),
134-
$this->defaultHeaders
139+
self::$defaultHeaders
135140
);
136141

137142
$exception = null;
@@ -159,6 +164,8 @@ public function testSendAsyncWithInvalidUri()
159164
* @dataProvider requestWithOutcomeProvider
160165
* @group integration
161166
*/
167+
#[Group('integration')]
168+
#[DataProvider('requestWithOutcomeProvider')]
162169
public function testSendAsyncRequestWithOutcome($uriAndOutcome, $protocolVersion, array $headers, $body)
163170
{
164171
if ('1.0' === $protocolVersion) {

src/HttpBaseTest.php

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
abstract class HttpBaseTest extends TestCase
1212
{
13-
use PhpUnitBackwardCompatibleTrait;
14-
1513
/**
1614
* @var string
1715
*/
@@ -36,7 +34,7 @@ abstract class HttpBaseTest extends TestCase
3634
/**
3735
* @var array
3836
*/
39-
protected $defaultHeaders = [
37+
protected static $defaultHeaders = [
4038
'Connection' => 'close',
4139
'User-Agent' => 'PHP HTTP Adapter',
4240
'Content-Length' => '0',
@@ -61,13 +59,13 @@ public static function tearDownAfterClass(): void
6159
}
6260
}
6361

64-
public function requestProvider(): array
62+
public static function requestProvider(): array
6563
{
6664
$sets = [
67-
'methods' => $this->getMethods(),
68-
'uris' => [$this->getUri()],
69-
'headers' => $this->getHeaders(),
70-
'body' => $this->getBodies(),
65+
'methods' => self::getMethods(),
66+
'uris' => [self::getUri()],
67+
'headers' => self::getHeaders(),
68+
'body' => self::getBodies(),
7169
];
7270

7371
$cartesianProduct = new CartesianProduct($sets);
@@ -84,21 +82,21 @@ public function requestProvider(): array
8482
});
8583
}
8684

87-
public function requestWithOutcomeProvider(): array
85+
public static function requestWithOutcomeProvider(): array
8886
{
8987
$sets = [
90-
'urisAndOutcomes' => $this->getUrisAndOutcomes(),
91-
'protocolVersions' => $this->getProtocolVersions(),
92-
'headers' => $this->getHeaders(),
93-
'body' => $this->getBodies(),
88+
'urisAndOutcomes' => self::getUrisAndOutcomes(),
89+
'protocolVersions' => self::getProtocolVersions(),
90+
'headers' => self::getHeaders(),
91+
'body' => self::getBodies(),
9492
];
9593

9694
$cartesianProduct = new CartesianProduct($sets);
9795

9896
return $cartesianProduct->compute();
9997
}
10098

101-
private function getMethods(): array
99+
private static function getMethods(): array
102100
{
103101
return [
104102
'GET',
@@ -116,7 +114,7 @@ private function getMethods(): array
116114
*
117115
* @return string|null
118116
*/
119-
protected function getUri(array $query = [])
117+
protected static function getUri(array $query = [])
120118
{
121119
return !empty($query)
122120
? PHPUnitUtility::getUri().'?'.http_build_query($query, '', '&')
@@ -134,25 +132,25 @@ protected function getInvalidUri()
134132
/**
135133
* @return array
136134
*/
137-
private function getUrisAndOutcomes()
135+
private static function getUrisAndOutcomes()
138136
{
139137
return [
140138
[
141-
$this->getUri(['client_error' => true]),
139+
self::getUri(['client_error' => true]),
142140
[
143141
'statusCode' => 400,
144142
'reasonPhrase' => 'Bad Request',
145143
],
146144
],
147145
[
148-
$this->getUri(['server_error' => true]),
146+
self::getUri(['server_error' => true]),
149147
[
150148
'statusCode' => 500,
151149
'reasonPhrase' => 'Internal Server Error',
152150
],
153151
],
154152
[
155-
$this->getUri(['redirect' => true]),
153+
self::getUri(['redirect' => true]),
156154
[
157155
'statusCode' => 302,
158156
'reasonPhrase' => 'Found',
@@ -165,41 +163,41 @@ private function getUrisAndOutcomes()
165163
/**
166164
* @return array
167165
*/
168-
private function getProtocolVersions()
166+
private static function getProtocolVersions()
169167
{
170168
return ['1.1', '1.0'];
171169
}
172170

173171
/**
174172
* @return string[]
175173
*/
176-
private function getHeaders()
174+
private static function getHeaders()
177175
{
178-
$headers = $this->defaultHeaders;
176+
$headers = self::$defaultHeaders;
179177
$headers['Accept-Charset'] = 'utf-8';
180178
$headers['Accept-Language'] = 'en';
181179

182180
return [
183-
$this->defaultHeaders,
181+
self::$defaultHeaders,
184182
$headers,
185183
];
186184
}
187185

188186
/**
189187
* @return array
190188
*/
191-
private function getBodies()
189+
private static function getBodies()
192190
{
193191
return [
194192
null,
195-
http_build_query($this->getData(), '', '&'),
193+
http_build_query(self::getData(), '', '&'),
196194
];
197195
}
198196

199197
/**
200198
* @return array
201199
*/
202-
private function getData()
200+
private static function getData()
203201
{
204202
return ['param1' => 'foo', 'param2' => ['bar', ['baz']]];
205203
}
@@ -223,7 +221,7 @@ protected function assertResponse(ResponseInterface $response, array $options =
223221
if (null === $options['body']) {
224222
$this->assertEmpty($response->getBody()->__toString());
225223
} else {
226-
$this->assertStringContainsString($options['body'], $response->getBody()->__toString());
224+
self::assertStringContainsString($options['body'], $response->getBody()->__toString());
227225
}
228226
}
229227

src/HttpClientTest.php

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

33
namespace Http\Client\Tests;
44

5+
use PHPUnit\Framework\Attributes\DataProvider;
6+
use PHPUnit\Framework\Attributes\Group;
57
use Psr\Http\Client\ClientInterface;
68
use Psr\Http\Client\NetworkExceptionInterface;
79

@@ -37,6 +39,8 @@ abstract protected function createHttpAdapter(): ClientInterface;
3739
* @dataProvider requestProvider
3840
* @group integration
3941
*/
42+
#[Group('integration')]
43+
#[DataProvider('requestProvider')]
4044
public function testSendRequest($method, $uri, array $headers, $body)
4145
{
4246
if (null != $body) {
@@ -65,6 +69,8 @@ public function testSendRequest($method, $uri, array $headers, $body)
6569
* @dataProvider requestWithOutcomeProvider
6670
* @group integration
6771
*/
72+
#[Group('integration')]
73+
#[DataProvider('requestWithOutcomeProvider')]
6874
public function testSendRequestWithOutcome($uriAndOutcome, $protocolVersion, array $headers, $body)
6975
{
7076
if ('1.0' === $protocolVersion) {
@@ -95,12 +101,13 @@ public function testSendRequestWithOutcome($uriAndOutcome, $protocolVersion, arr
95101
/**
96102
* @group integration
97103
*/
104+
#[Group('integration')]
98105
public function testSendWithInvalidUri()
99106
{
100107
$request = self::$messageFactory->createRequest(
101108
'GET',
102109
$this->getInvalidUri(),
103-
$this->defaultHeaders
110+
self::$defaultHeaders
104111
);
105112

106113
$this->expectException(NetworkExceptionInterface::class);

src/HttpFeatureTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
abstract class HttpFeatureTest extends TestCase
1111
{
12-
use PhpUnitBackwardCompatibleTrait;
13-
1412
/**
1513
* @var MessageFactory
1614
*/

src/PhpUnitBackwardCompatibleTrait.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use PHPUnit\Framework\TestCase;
66

7+
/**
8+
* @deprecated this trait was to help using phpunit 7 and 8 which are obsolete. this trait will be removed in the next major version.
9+
*/
710
trait PhpUnitBackwardCompatibleTrait
811
{
912
public static function assertStringContainsString(string $needle, string $haystack, string $message = ''): void

0 commit comments

Comments
 (0)