Skip to content

Commit 3a25887

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 3a25887

21 files changed

+86
-92
lines changed

Diff for: .github/workflows/guzzle.yml

+1-1
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 }}

Diff for: .github/workflows/laminas-legacy.yml

+1-1
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 }}

Diff for: .github/workflows/nyholm.yml

+1-1
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 }}

Diff for: .github/workflows/ringcentral.yml

+1-1
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 }}

Diff for: .gitignore

+1
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

Diff for: composer.json

+2-2
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": {

Diff for: phpunit.xml.dist

+19-28
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>

Diff for: src/BaseTest.php

+17-11
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);

Diff for: src/MessageTrait.php

+2-7
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
}

Diff for: src/RequestIntegrationTest.php

+1-1
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],

Diff for: src/ResponseIntegrationTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function testStatusCodeInvalidArgument($statusCode)
8080
}
8181
}
8282

83-
public function getInvalidStatusCodeArguments()
83+
public static function getInvalidStatusCodeArguments()
8484
{
8585
return [
8686
'true' => [true],

Diff for: src/ServerRequestIntegrationTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function testGetParsedBody($value)
9999
$this->assertEquals($value, $new->getParsedBody());
100100
}
101101

102-
public function validParsedBodyParams()
102+
public static function validParsedBodyParams()
103103
{
104104
return [
105105
[null],
@@ -125,7 +125,7 @@ public function testGetParsedBodyInvalid($value)
125125
}
126126
}
127127

128-
public function invalidParsedBodyParams()
128+
public static function invalidParsedBodyParams()
129129
{
130130
return [
131131
[4711],

Diff for: src/StreamIntegrationTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ public function testGetContentsError()
315315

316316
fclose($resource);
317317

318-
$this->expectException(\RuntimeException::class);
318+
$this->expectException(class_exists(\Throwable::class) ? \Throwable::class : \RuntimeException::class);
319319
$stream->getContents();
320320
}
321321
}

Diff for: src/UploadedFileIntegrationTest.php

+2-7
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,8 @@ public function testGetSize()
102102

103103
$file = $this->createSubject();
104104
$size = $file->getSize();
105-
if (false !== $size) {
106-
// @TODO remove when package require phpunit 9.1
107-
if (function_exists('PHPUnit\Framework\assertMatchesRegularExpression')) {
108-
$this->assertMatchesRegularExpression('|^[0-9]+$|', (string) $size);
109-
} else {
110-
$this->assertRegExp('|^[0-9]+$|', (string) $size);
111-
}
105+
if (null !== $size) {
106+
$this->assertMatchesRegularExpression('|^[0-9]+$|', (string) $size);
112107
} else {
113108
$this->assertNull($size);
114109
}

Diff for: src/UriIntegrationTest.php

+28-22
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function testWithSchemeInvalidArguments($schema)
6969
}
7070
}
7171

72-
public function getInvalidSchemaArguments()
72+
public static function getInvalidSchemaArguments()
7373
{
7474
return [
7575
[true],
@@ -155,7 +155,7 @@ public function testPort()
155155
/**
156156
* @dataProvider getPaths
157157
*/
158-
public function testPath(UriInterface $uri, $expected)
158+
public function testPath(UriInterface $uri, string $expected)
159159
{
160160
if (isset($this->skippedTests[__FUNCTION__])) {
161161
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
@@ -164,22 +164,24 @@ public function testPath(UriInterface $uri, $expected)
164164
$this->assertSame($expected, $uri->getPath());
165165
}
166166

167-
public function getPaths()
167+
public static function getPaths()
168168
{
169+
$test = new static('uriprovider');
170+
169171
return [
170-
[$this->createUri('http://www.foo.com/'), '/'],
171-
[$this->createUri('http://www.foo.com'), ''],
172-
[$this->createUri('foo/bar'), 'foo/bar'],
173-
[$this->createUri('http://www.foo.com/foo bar'), '/foo%20bar'],
174-
[$this->createUri('http://www.foo.com/foo%20bar'), '/foo%20bar'],
175-
[$this->createUri('http://www.foo.com/foo%2fbar'), '/foo%2fbar'],
172+
[$test->createUri('http://www.foo.com/'), '/'],
173+
[$test->createUri('http://www.foo.com'), ''],
174+
[$test->createUri('foo/bar'), 'foo/bar'],
175+
[$test->createUri('http://www.foo.com/foo bar'), '/foo%20bar'],
176+
[$test->createUri('http://www.foo.com/foo%20bar'), '/foo%20bar'],
177+
[$test->createUri('http://www.foo.com/foo%2fbar'), '/foo%2fbar'],
176178
];
177179
}
178180

179181
/**
180182
* @dataProvider getQueries
181183
*/
182-
public function testQuery(UriInterface $uri, $expected)
184+
public function testQuery(UriInterface $uri, string $expected)
183185
{
184186
if (isset($this->skippedTests[__FUNCTION__])) {
185187
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
@@ -188,21 +190,23 @@ public function testQuery(UriInterface $uri, $expected)
188190
$this->assertSame($expected, $uri->getQuery());
189191
}
190192

191-
public function getQueries()
193+
public static function getQueries()
192194
{
195+
$test = new static('uriprovider');
196+
193197
return [
194-
[$this->createUri('http://www.foo.com'), ''],
195-
[$this->createUri('http://www.foo.com?'), ''],
196-
[$this->createUri('http://www.foo.com?foo=bar'), 'foo=bar'],
197-
[$this->createUri('http://www.foo.com?foo=bar%26baz'), 'foo=bar%26baz'],
198-
[$this->createUri('http://www.foo.com?foo=bar&baz=biz'), 'foo=bar&baz=biz'],
198+
[$test->createUri('http://www.foo.com'), ''],
199+
[$test->createUri('http://www.foo.com?'), ''],
200+
[$test->createUri('http://www.foo.com?foo=bar'), 'foo=bar'],
201+
[$test->createUri('http://www.foo.com?foo=bar%26baz'), 'foo=bar%26baz'],
202+
[$test->createUri('http://www.foo.com?foo=bar&baz=biz'), 'foo=bar&baz=biz'],
199203
];
200204
}
201205

202206
/**
203207
* @dataProvider getFragments
204208
*/
205-
public function testFragment(UriInterface $uri, $expected)
209+
public function testFragment(UriInterface $uri, string $expected)
206210
{
207211
if (isset($this->skippedTests[__FUNCTION__])) {
208212
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
@@ -211,13 +215,15 @@ public function testFragment(UriInterface $uri, $expected)
211215
$this->assertEquals($expected, $uri->getFragment());
212216
}
213217

214-
public function getFragments()
218+
public static function getFragments()
215219
{
220+
$test = new static('uriprovider');
221+
216222
return [
217-
[$this->createUri('http://www.foo.com'), ''],
218-
[$this->createUri('http://www.foo.com#'), ''],
219-
[$this->createUri('http://www.foo.com#foo'), 'foo'],
220-
[$this->createUri('http://www.foo.com#foo%20bar'), 'foo%20bar'],
223+
[$test->createUri('http://www.foo.com'), ''],
224+
[$test->createUri('http://www.foo.com#'), ''],
225+
[$test->createUri('http://www.foo.com#foo'), 'foo'],
226+
[$test->createUri('http://www.foo.com#foo%20bar'), 'foo%20bar'],
221227
];
222228
}
223229

Diff for: tests/Guzzle/RequestTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function createSubject()
1616
return new Request('GET', '/');
1717
}
1818

19-
public function getInvalidHeaderArguments()
19+
public static function getInvalidHeaderArguments()
2020
{
2121
$testCases = parent::getInvalidHeaderArguments();
2222

0 commit comments

Comments
 (0)