Skip to content

Commit 367c2b0

Browse files
nyamsproddbu
authored andcommitted
Add support for PHPUnit10 and remove support for PHPUnit8
* Normalize class import and class alias * Remove PHP7.2 from github workflows * Migrate phpunit.xml.dist configuration file * Using FQN for PSR interfaces
1 parent f725461 commit 367c2b0

17 files changed

+82
-88
lines changed

.github/workflows/guzzle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
14+
php: [ '7.3', '7.4', '8.0', '8.1', '8.2' ]
1515
uses: ./.github/workflows/integration.yml
1616
with:
1717
php: ${{ matrix.php }}

.github/workflows/laminas-legacy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
php: [ '7.2', '7.3', '7.4' ]
14+
php: [ '7.3', '7.4' ]
1515
uses: ./.github/workflows/integration.yml
1616
with:
1717
php: ${{ matrix.php }}

.github/workflows/nyholm.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
14+
php: [ '7.3', '7.4', '8.0', '8.1', '8.2' ]
1515
uses: ./.github/workflows/integration.yml
1616
with:
1717
php: ${{ matrix.php }}

.github/workflows/ringcentral.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
14+
php: [ '7.3', '7.4', '8.0', '8.1', '8.2' ]
1515
uses: ./.github/workflows/integration.yml
1616
with:
1717
php: ${{ matrix.php }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/.tmp
22
/.phpunit.result.cache
3+
/.phpunit.cache
34
/behat.yml
45
/build/
56
/composer.lock

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
}
1515
],
1616
"require": {
17-
"php": "^7.2 || ^8.0",
18-
"phpunit/phpunit": "^8.0 || ^9.3",
17+
"php": "^7.3 || ^8.0",
18+
"phpunit/phpunit": "^9.3 || ^10.0",
1919
"psr/http-message": "^1.0 || ^2.0"
2020
},
2121
"require-dev": {

phpunit.xml.dist

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,39 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
3-
<phpunit backupGlobals="false"
4-
backupStaticAttributes="true"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false"
11-
bootstrap="vendor/autoload.php"
12-
>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
backupGlobals="false"
5+
colors="true"
6+
processIsolation="false"
7+
stopOnFailure="false"
8+
bootstrap="vendor/autoload.php"
9+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
10+
cacheDirectory=".phpunit.cache"
11+
backupStaticProperties="true"
12+
>
13+
<coverage>
14+
<include>
15+
<directory>./src</directory>
16+
</include>
17+
</coverage>
1318
<testsuites>
1419
<testsuite name="Guzzle">
1520
<directory>./tests/Guzzle/</directory>
1621
</testsuite>
17-
1822
<testsuite name="RingCentral">
1923
<directory>./tests/RingCentral/</directory>
2024
</testsuite>
21-
2225
<testsuite name="Slim">
23-
<directory>./tests/Slim/</directory>
26+
<directory>./tests/Slim/</directory>
2427
</testsuite>
25-
2628
<testsuite name="Laminas">
27-
<directory>./tests/Laminas/</directory>
29+
<directory>./tests/Laminas/</directory>
2830
</testsuite>
29-
3031
<testsuite name="Nyholm">
31-
<directory>./vendor/nyholm/psr7/tests/Integration/</directory>
32+
<directory>./vendor/nyholm/psr7/tests/Integration/</directory>
3233
</testsuite>
3334

3435
<testsuite name="HttpSoft">
3536
<directory>./vendor/httpsoft/http-message/tests/Integration/</directory>
3637
</testsuite>
3738
</testsuites>
38-
39-
<filter>
40-
<whitelist>
41-
<directory>./</directory>
42-
<exclude>
43-
<directory>./Tests</directory>
44-
<directory>./vendor</directory>
45-
</exclude>
46-
</whitelist>
47-
</filter>
4839
</phpunit>

src/BaseTest.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@
1313
use Laminas\Diactoros\UploadedFile as LaminasUploadedFile;
1414
use Nyholm\Psr7\Factory\Psr17Factory as NyholmFactory;
1515
use PHPUnit\Framework\TestCase;
16-
use Psr\Http\Message\UriInterface;
1716
use RingCentral\Psr7\Uri as RingCentralUri;
1817
use function RingCentral\Psr7\stream_for as ring_central_stream_for;
18+
use GuzzleHttp\Psr7\Utils as GuzzleUtils;
19+
use Http\Message\StreamFactory as HttplugStreamFactory;
20+
use Http\Message\UriFactory as HttplugUriFactory;
21+
use Psr\Http\Message\StreamFactoryInterface as PsrStreamFactoryInterface;
22+
use Psr\Http\Message\UploadedFileFactoryInterface as PsrUploadedFileFactoryInterface;
23+
use Psr\Http\Message\UriFactoryInterface as PsrUriFactoryInterface;
24+
use Psr\Http\Message\UriInterface as PsrUriInterface;
1925
use Slim\Psr7\Uri as SlimUri;
2026
use Slim\Psr7\Factory\UriFactory as SlimUriFactory;
2127
use Slim\Psr7\Factory\StreamFactory as SlimStreamFactory;
@@ -36,18 +42,18 @@ protected function buildUri($uri)
3642
if (defined('URI_FACTORY')) {
3743
$factoryClass = URI_FACTORY;
3844
$factory = new $factoryClass();
39-
if ($factory instanceof \Http\Message\UriFactory) {
45+
if ($factory instanceof HttplugUriFactory) {
4046
return $factory->createUri($uri);
4147
}
42-
if ($factory instanceof \Psr\Http\Message\UriFactoryInterface) {
43-
if ($uri instanceof UriInterface) {
48+
if ($factory instanceof PsrUriFactoryInterface) {
49+
if ($uri instanceof PsrUriInterface) {
4450
return $uri;
4551
}
4652

4753
return $factory->createUri($uri);
4854
}
4955

50-
throw new \RuntimeException('Constant "URI_FACTORY" must be a reference to a Http\Message\UriFactory or \Psr\Http\Message\UriFactoryInterface');
56+
throw new \RuntimeException('Constant "URI_FACTORY" must be a reference to a '.HttplugUriFactory::class.' or '.PsrUriFactoryInterface::class);
5157
}
5258

5359
if (class_exists(HttpSoftUri::class)) {
@@ -86,22 +92,22 @@ protected function buildStream($data)
8692
if (defined('STREAM_FACTORY')) {
8793
$factoryClass = STREAM_FACTORY;
8894
$factory = new $factoryClass();
89-
if ($factory instanceof \Http\Message\StreamFactory) {
95+
if ($factory instanceof HttplugStreamFactory) {
9096
return $factory->createStream($data);
9197
}
92-
if ($factory instanceof \Psr\Http\Message\StreamFactoryInterface) {
98+
if ($factory instanceof PsrStreamFactoryInterface) {
9399
if (is_string($data)) {
94100
return $factory->createStream($data);
95101
}
96102

97103
return $factory->createStreamFromResource($data);
98104
}
99105

100-
throw new \RuntimeException('Constant "STREAM_FACTORY" must be a reference to a Http\Message\StreamFactory or \Psr\Http\Message\StreamFactoryInterface');
106+
throw new \RuntimeException('Constant "STREAM_FACTORY" must be a reference to a '.HttplugStreamFactory::class.' or '.PsrStreamFactoryInterface::class);
101107
}
102108

103109
if (class_exists(GuzzleStream::class)) {
104-
return \GuzzleHttp\Psr7\Utils::streamFor($data);
110+
return GuzzleUtils::streamFor($data);
105111
}
106112

107113
$factory = null;
@@ -137,8 +143,8 @@ protected function buildUploadableFile($data)
137143
if (defined('UPLOADED_FILE_FACTORY')) {
138144
$factoryClass = UPLOADED_FILE_FACTORY;
139145
$factory = new $factoryClass();
140-
if (!$factory instanceof \Psr\Http\Message\UploadedFileFactoryInterface) {
141-
throw new \RuntimeException('Constant "UPLOADED_FILE_FACTORY" must be a reference to a Psr\Http\Message\UploadedFileFactoryInterface');
146+
if (!$factory instanceof PsrUploadedFileFactoryInterface) {
147+
throw new \RuntimeException('Constant "UPLOADED_FILE_FACTORY" must be a reference to a '.PsrUploadedFileFactoryInterface::class);
142148
}
143149

144150
$stream = $this->buildStream($data);

src/MessageTrait.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public function testWithHeaderInvalidArguments($name, $value)
160160
}
161161
}
162162

163-
public function getInvalidHeaderArguments()
163+
public static function getInvalidHeaderArguments()
164164
{
165165
return [
166166
[[], 'foo'],
@@ -288,11 +288,6 @@ public function testBody()
288288

289289
private function assertMatchesRegexp(string $pattern, string $string, string $message = ''): void
290290
{
291-
// @TODO remove when package require phpunit 9.1
292-
if (function_exists('PHPUnit\Framework\assertMatchesRegularExpression')) {
293-
$this->assertMatchesRegularExpression($pattern, $string, $message);
294-
} else {
295-
$this->assertRegExp($pattern, $string, $message);
296-
}
291+
$this->assertMatchesRegularExpression($pattern, $string, $message);
297292
}
298293
}

src/RequestIntegrationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function testMethodWithInvalidArguments($method)
118118
}
119119
}
120120

121-
public function getInvalidMethods()
121+
public static function getInvalidMethods()
122122
{
123123
return [
124124
'null' => [null],

0 commit comments

Comments
 (0)