Skip to content

Commit f5711a3

Browse files
committed
adjust to integration tests 4 and modernize phpunit usage
1 parent cc3b486 commit f5711a3

11 files changed

+43
-63
lines changed

composer.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
"name": "Михаил Красильников",
1313
"email": "[email protected]"
1414
}],
15-
"prefer-stable": true,
16-
"minimum-stability": "dev",
1715
"require": {
1816
"php": "^7.4 || ^8.0",
1917
"ext-curl": "*",
@@ -26,8 +24,8 @@
2624
},
2725
"require-dev": {
2826
"guzzlehttp/psr7": "^2.0",
29-
"php-http/client-integration-tests": "^3.0",
30-
"phpunit/phpunit": "^7.5 || ^9.4",
27+
"php-http/client-integration-tests": "dev-cleanup-major",
28+
"phpunit/phpunit": "^9.6.17 || ^10.0 || ^11.0 || ^12.0",
3129
"laminas/laminas-diactoros": "^2.0 || ^3.0",
3230
"php-http/message-factory": "^1.1"
3331
},

phpunit.xml.dist

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
43
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/7.0/phpunit.xsd"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
65
bootstrap="tests/bootstrap.php"
76
colors="true"
7+
displayDetailsOnTestsThatTriggerErrors="true"
8+
displayDetailsOnTestsThatTriggerNotices="true"
9+
displayDetailsOnTestsThatTriggerWarnings="true"
10+
displayDetailsOnPhpunitDeprecations="true"
811
>
912
<php>
1013
<server name="TEST_SERVER" value="http://127.0.0.1:10000/server.php"/>
1114
</php>
1215

1316
<testsuites>
1417

15-
<testsuite name="All">
16-
<directory>tests</directory>
17-
</testsuite>
18-
1918
<testsuite name="Unit">
2019
<directory>tests/Unit</directory>
2120
</testsuite>
@@ -26,10 +25,10 @@
2625

2726
</testsuites>
2827

29-
<filter>
30-
<whitelist>
28+
<source>
29+
<include>
3130
<directory>src</directory>
32-
</whitelist>
33-
</filter>
31+
</include>
32+
</source>
3433

3534
</phpunit>

tests/Functional/HttpAsyncClientDiactorosTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
*/
1515
class HttpAsyncClientDiactorosTest extends HttpAsyncClientTestCase
1616
{
17-
/**
18-
* {@inheritdoc}
19-
*/
2017
protected function createHttpAsyncClient(): HttpAsyncClient
2118
{
2219
return new Client(new ResponseFactory(), new StreamFactory());

tests/Functional/HttpAsyncClientGuzzleTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
*/
1414
class HttpAsyncClientGuzzleTest extends HttpAsyncClientTestCase
1515
{
16-
/**
17-
* {@inheritdoc}
18-
*/
1916
protected function createHttpAsyncClient(): HttpAsyncClient
2017
{
2118
return new Client(new HttpFactory(), new HttpFactory());

tests/Functional/HttpAsyncClientTestCase.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
namespace Http\Client\Curl\Tests\Functional;
66

77
use Http\Client\Tests\HttpAsyncClientTest;
8+
use PHPUnit\Framework\Attributes\DataProvider;
89

910
/**
1011
* Base class for asynchronous functional client tests.
1112
*/
1213
abstract class HttpAsyncClientTestCase extends HttpAsyncClientTest
1314
{
1415
/**
15-
* {@inheritdoc}
16-
*
1716
* @dataProvider requestProvider
1817
*/
19-
public function testAsyncSendRequest($httpMethod, $uri, array $httpHeaders, $requestBody): void
18+
#[DataProvider('requestProvider')]
19+
public function testAsyncSendRequest(string $httpMethod, string $uri, array $httpHeaders, ?string $requestBody): void
2020
{
2121
if ($requestBody !== null && in_array($httpMethod, ['GET', 'HEAD', 'TRACE'], true)) {
2222
self::markTestSkipped('cURL can not send body using '.$httpMethod);
@@ -30,15 +30,14 @@ public function testAsyncSendRequest($httpMethod, $uri, array $httpHeaders, $req
3030
}
3131

3232
/**
33-
* {@inheritdoc}
34-
*
3533
* @dataProvider requestWithOutcomeProvider
3634
*/
35+
#[DataProvider('requestWithOutcomeProvider')]
3736
public function testSendAsyncRequestWithOutcome(
38-
$uriAndOutcome,
39-
$httpVersion,
37+
array $uriAndOutcome,
38+
string $httpVersion,
4039
array $httpHeaders,
41-
$requestBody
40+
?string $requestBody
4241
): void {
4342
if ( $requestBody !== null) {
4443
self::markTestSkipped('cURL can not send body using GET');

tests/Functional/HttpClientDiactorosTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
use Http\Client\Curl\Client;
99
use Psr\Http\Client\ClientInterface;
10-
use Http\Client\HttpClient;
1110
use Psr\Http\Message\StreamInterface;
1211
use Laminas\Diactoros\ResponseFactory;
1312
use Laminas\Diactoros\Stream;

tests/Functional/HttpClientGuzzleTest.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,11 @@
1515
*/
1616
class HttpClientGuzzleTest extends HttpClientTestCase
1717
{
18-
/**
19-
* {@inheritdoc}
20-
*/
2118
protected function createHttpAdapter(): ClientInterface
2219
{
2320
return new Client(new HttpFactory(), new HttpFactory());
2421
}
2522

26-
/**
27-
* {@inheritdoc}
28-
*/
2923
protected function createFileStream(string $filename): StreamInterface
3024
{
3125
return new Stream(fopen($filename, 'r'));

tests/Functional/HttpClientTestCase.php

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Http\Client\Tests\HttpClientTest;
88
use Http\Client\Tests\PHPUnitUtility;
9+
use PHPUnit\Framework\Attributes\DataProvider;
910
use Psr\Http\Message\StreamInterface;
1011

1112
/**
@@ -18,7 +19,7 @@ abstract class HttpClientTestCase extends HttpClientTest
1819
*
1920
* @var string[]
2021
*/
21-
protected $tmpFiles = [];
22+
protected array $tmpFiles = [];
2223

2324
public function testSendLargeFile(): void
2425
{
@@ -31,12 +32,9 @@ public function testSendLargeFile(): void
3132
fclose($fd);
3233
$body = $this->createFileStream($filename);
3334

34-
$request = self::$messageFactory->createRequest(
35-
'POST',
36-
PHPUnitUtility::getUri(),
37-
['content-length' => 1024 * 2048],
38-
$body
39-
);
35+
$request = self::$requestFactory->createRequest('POST', PHPUnitUtility::getUri());
36+
$request = $request->withHeader('content-length', 1024 * 2048);
37+
$request = $request->withBody($body);
4038

4139
$response = $this->httpAdapter->sendRequest($request);
4240
$this->assertResponse(
@@ -52,11 +50,10 @@ public function testSendLargeFile(): void
5250
}
5351

5452
/**
55-
* {@inheritdoc}
56-
*
5753
* @dataProvider requestProvider
5854
*/
59-
public function testSendRequest($httpMethod, $uri, array $httpHeaders, $requestBody): void
55+
#[DataProvider('requestProvider')]
56+
public function testSendRequest(string $httpMethod, string $uri, array $httpHeaders, ?string $requestBody): void
6057
{
6158
if ($requestBody !== null && in_array($httpMethod, ['GET', 'HEAD', 'TRACE'], true)) {
6259
self::markTestSkipped('cURL can not send body using '.$httpMethod);
@@ -70,15 +67,14 @@ public function testSendRequest($httpMethod, $uri, array $httpHeaders, $requestB
7067
}
7168

7269
/**
73-
* {@inheritdoc}
74-
*
7570
* @dataProvider requestWithOutcomeProvider
7671
*/
72+
#[DataProvider('requestWithOutcomeProvider')]
7773
public function testSendRequestWithOutcome(
78-
$uriAndOutcome,
79-
$httpVersion,
74+
array $uriAndOutcome,
75+
string $httpVersion,
8076
array $httpHeaders,
81-
$requestBody
77+
?string $requestBody
8278
): void {
8379
if ($requestBody !== null) {
8480
self::markTestSkipped('cURL can not send body using GET');
@@ -95,8 +91,6 @@ abstract protected function createFileStream(string $filename): StreamInterface;
9591

9692
/**
9793
* Create temporary file.
98-
*
99-
* @return string Filename
10094
*/
10195
protected function createTempFile(): string
10296
{

tests/Unit/ClientTest.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ public function testExpectHeaderIsEmpty(): void
4242
$client = $this->createMock(Client::class);
4343

4444
$createHeaders = new \ReflectionMethod(Client::class, 'createHeaders');
45-
$createHeaders->setAccessible(true);
45+
if (PHP_VERSION_ID < 80100) {
46+
$createHeaders->setAccessible(true);
47+
}
4648

4749
$request = new Request();
4850

@@ -61,7 +63,9 @@ public function testExpectHeaderIsEmpty2(): void
6163
$client = $this->createMock(Client::class);
6264

6365
$createHeaders = new \ReflectionMethod(Client::class, 'createHeaders');
64-
$createHeaders->setAccessible(true);
66+
if (PHP_VERSION_ID < 80100) {
67+
$createHeaders->setAccessible(true);
68+
}
6569

6670
$request = new Request();
6771
$request = $request->withHeader('content-length', '0');
@@ -76,7 +80,9 @@ public function testRewindLargeStream(): void
7680
$client = $this->createMock(Client::class);
7781

7882
$bodyOptions = new \ReflectionMethod(Client::class, 'addRequestBodyOptions');
79-
$bodyOptions->setAccessible(true);
83+
if (PHP_VERSION_ID < 80100) {
84+
$bodyOptions->setAccessible(true);
85+
}
8086

8187
$content = 'abcdef';
8288
while (strlen($content) < 1024 * 1024 + 100) {
@@ -99,7 +105,9 @@ public function testRewindStream(): void
99105
$client = $this->createMock(Client::class);
100106

101107
$bodyOptions = new \ReflectionMethod(Client::class, 'addRequestBodyOptions');
102-
$bodyOptions->setAccessible(true);
108+
if (PHP_VERSION_ID < 80100) {
109+
$bodyOptions->setAccessible(true);
110+
}
103111

104112
$body = Utils::streamFor('abcdef');
105113
$body->seek(3);

tests/Unit/CurlPromiseTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ public function testCoreCallWaitFulfilled(): void
2121
{
2222
$core = $this->createMock(PromiseCore::class);
2323
$runner = $this->getMockBuilder(MultiRunner::class)->disableOriginalConstructor()
24-
->setMethods(['wait'])->getMock();
25-
/** @var MultiRunner|\PHPUnit_Framework_MockObject_MockObject $runner */
24+
->onlyMethods(['wait'])->getMock();
2625
$promise = new CurlPromise($core, $runner);
2726

2827
$runner->expects(self::once())->method('wait')->with($core);
@@ -37,7 +36,6 @@ public function testCoreCallWaitRejected(): void
3736
{
3837
$core = $this->createMock(PromiseCore::class);
3938
$runner = $this->getMockBuilder(MultiRunner::class)->disableOriginalConstructor()->getMock();
40-
/** @var MultiRunner|\PHPUnit_Framework_MockObject_MockObject $runner */
4139
$promise = new CurlPromise($core, $runner);
4240

4341
$runner->expects(self::once())->method('wait')->with($core);
@@ -55,8 +53,7 @@ public function testCoreCalls(): void
5553
{
5654
$core = $this->createMock(PromiseCore::class);
5755
$runner = $this->getMockBuilder(MultiRunner::class)->disableOriginalConstructor()
58-
->setMethods(['wait'])->getMock();
59-
/** @var MultiRunner|\PHPUnit_Framework_MockObject_MockObject $runner */
56+
->onlyMethods(['wait'])->getMock();
6057
$promise = new CurlPromise($core, $runner);
6158

6259
$onFulfill = function () {

0 commit comments

Comments
 (0)