From f9481d31db3a3454c5ef6daafad7ec30993b6b2f Mon Sep 17 00:00:00 2001 From: ignace nyamagana butera Date: Mon, 27 Feb 2023 17:51:17 +0100 Subject: [PATCH 1/6] Add support for PHPUnit10 and remove support for PHPUnit8 --- composer.json | 4 +-- src/BaseTest.php | 24 ++++++++----- src/MessageTrait.php | 9 ++--- src/RequestIntegrationTest.php | 2 +- src/ResponseIntegrationTest.php | 2 +- src/ServerRequestIntegrationTest.php | 4 +-- src/UploadedFileIntegrationTest.php | 7 +--- src/UriIntegrationTest.php | 50 ++++++++++++++-------------- tests/Guzzle/RequestTest.php | 2 +- tests/Guzzle/ResponseTest.php | 2 +- 10 files changed, 51 insertions(+), 55 deletions(-) diff --git a/composer.json b/composer.json index 7ca39e0..bf09bda 100644 --- a/composer.json +++ b/composer.json @@ -14,8 +14,8 @@ } ], "require": { - "php": "^7.2 || ^8.0", - "phpunit/phpunit": "^8.0 || ^9.3", + "php": "^7.3 || ^8.0", + "phpunit/phpunit": "^9.3 || ^10.0", "psr/http-message": "^1.0" }, "require-dev": { diff --git a/src/BaseTest.php b/src/BaseTest.php index 43dd292..d2bf7a2 100644 --- a/src/BaseTest.php +++ b/src/BaseTest.php @@ -5,12 +5,18 @@ use GuzzleHttp\Psr7\Stream as GuzzleStream; use GuzzleHttp\Psr7\UploadedFile as GuzzleUploadedFile; use GuzzleHttp\Psr7\Uri as GuzzleUri; +use GuzzleHttp\Psr7\Utils; +use Http\Message\StreamFactory; +use Http\Message\UriFactory; +use Laminas\Diactoros\Stream as ZendStream; +use Laminas\Diactoros\Uri as ZendUri; +use Laminas\Diactoros\UploadedFile as ZendUploadedFile; use PHPUnit\Framework\TestCase; +use Psr\Http\Message\StreamFactoryInterface; +use Psr\Http\Message\UploadedFileFactoryInterface; +use Psr\Http\Message\UriFactoryInterface; use Psr\Http\Message\UriInterface; use Slim\Psr7\Uri as SlimUri; -use Zend\Diactoros\Stream as ZendStream; -use Zend\Diactoros\Uri as ZendUri; -use Zend\Diactoros\UploadedFile as ZendUploadedFile; /** * @author Tobias Nyholm @@ -27,10 +33,10 @@ protected function buildUri($uri) if (defined('URI_FACTORY')) { $factoryClass = URI_FACTORY; $factory = new $factoryClass(); - if ($factory instanceof \Http\Message\UriFactory) { + if ($factory instanceof UriFactory) { return $factory->createUri($uri); } - if ($factory instanceof \Psr\Http\Message\UriFactoryInterface) { + if ($factory instanceof UriFactoryInterface) { if ($uri instanceof UriInterface) { return $uri; } @@ -61,10 +67,10 @@ protected function buildStream($data) if (defined('STREAM_FACTORY')) { $factoryClass = STREAM_FACTORY; $factory = new $factoryClass(); - if ($factory instanceof \Http\Message\StreamFactory) { + if ($factory instanceof StreamFactory) { return $factory->createStream($data); } - if ($factory instanceof \Psr\Http\Message\StreamFactoryInterface) { + if ($factory instanceof StreamFactoryInterface) { if (is_string($data)) { return $factory->createStream($data); } else { @@ -76,7 +82,7 @@ protected function buildStream($data) } if (class_exists(GuzzleStream::class)) { - return \GuzzleHttp\Psr7\Utils::streamFor($data); + return Utils::streamFor($data); } if (class_exists(ZendStream::class)) { @@ -91,7 +97,7 @@ protected function buildUploadableFile($data) if (defined('UPLOADED_FILE_FACTORY')) { $factoryClass = UPLOADED_FILE_FACTORY; $factory = new $factoryClass(); - if (!$factory instanceof \Psr\Http\Message\UploadedFileFactoryInterface) { + if (!$factory instanceof UploadedFileFactoryInterface) { throw new \RuntimeException('Constant "UPLOADED_FILE_FACTORY" must be a reference to a Psr\Http\Message\UploadedFileFactoryInterface'); } diff --git a/src/MessageTrait.php b/src/MessageTrait.php index 5b30d16..4a78fee 100644 --- a/src/MessageTrait.php +++ b/src/MessageTrait.php @@ -141,7 +141,7 @@ public function testWithHeaderInvalidArguments($name, $value) $initialMessage->withHeader($name, $value); } - public function getInvalidHeaderArguments() + public static function getInvalidHeaderArguments() { return [ [[], 'foo'], @@ -254,11 +254,6 @@ public function testBody() private function assertMatchesRegexp(string $pattern, string $string, string $message = ''): void { - // @TODO remove when package require phpunit 9.1 - if (function_exists('PHPUnit\Framework\assertMatchesRegularExpression')) { - $this->assertMatchesRegularExpression($pattern, $string, $message); - } else { - $this->assertRegExp($pattern, $string, $message); - } + $this->assertMatchesRegularExpression($pattern, $string, $message); } } diff --git a/src/RequestIntegrationTest.php b/src/RequestIntegrationTest.php index cd514eb..60ff8b9 100644 --- a/src/RequestIntegrationTest.php +++ b/src/RequestIntegrationTest.php @@ -100,7 +100,7 @@ public function testMethodWithInvalidArguments($method) $this->request->withMethod($method); } - public function getInvalidMethods() + public static function getInvalidMethods() { return [ [null], diff --git a/src/ResponseIntegrationTest.php b/src/ResponseIntegrationTest.php index 9abd790..a69c3dc 100644 --- a/src/ResponseIntegrationTest.php +++ b/src/ResponseIntegrationTest.php @@ -62,7 +62,7 @@ public function testStatusCodeInvalidArgument($statusCode) $this->response->withStatus($statusCode); } - public function getInvalidStatusCodeArguments() + public static function getInvalidStatusCodeArguments() { return [ [true], diff --git a/src/ServerRequestIntegrationTest.php b/src/ServerRequestIntegrationTest.php index 82e00c7..ad4bc50 100644 --- a/src/ServerRequestIntegrationTest.php +++ b/src/ServerRequestIntegrationTest.php @@ -103,7 +103,7 @@ public function testGetParsedBody($value) $this->assertEquals($value, $new->getParsedBody()); } - public function validParsedBodyParams() + public static function validParsedBodyParams() { return [ [null], @@ -129,7 +129,7 @@ public function testGetParsedBodyInvalid($value) } } - public function invalidParsedBodyParams() + public static function invalidParsedBodyParams() { return [ [4711], diff --git a/src/UploadedFileIntegrationTest.php b/src/UploadedFileIntegrationTest.php index d195ee6..c505bd6 100644 --- a/src/UploadedFileIntegrationTest.php +++ b/src/UploadedFileIntegrationTest.php @@ -103,12 +103,7 @@ public function testGetSize() $file = $this->createSubject(); $size = $file->getSize(); if ($size) { - // @TODO remove when package require phpunit 9.1 - if (function_exists('PHPUnit\Framework\assertMatchesRegularExpression')) { - $this->assertMatchesRegularExpression('|^[0-9]+$|', (string) $size); - } else { - $this->assertRegExp('|^[0-9]+$|', (string) $size); - } + $this->assertMatchesRegularExpression('|^[0-9]+$|', (string) $size); } else { $this->assertNull($size); } diff --git a/src/UriIntegrationTest.php b/src/UriIntegrationTest.php index ee998e0..b5d84bf 100644 --- a/src/UriIntegrationTest.php +++ b/src/UriIntegrationTest.php @@ -51,7 +51,7 @@ public function testWithSchemeInvalidArguments($schema) $this->createUri('/')->withScheme($schema); } - public function getInvalidSchemaArguments() + public static function getInvalidSchemaArguments() { return [ [true], @@ -134,69 +134,69 @@ public function testPort() /** * @dataProvider getPaths */ - public function testPath(UriInterface $uri, $expected) + public function testPath(string $uri, string $expected) { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } - $this->assertSame($expected, $uri->getPath()); + $this->assertSame($expected, $this->createUri($uri)->getPath()); } - public function getPaths() + public static function getPaths() { return [ - [$this->createUri('http://www.foo.com/'), '/'], - [$this->createUri('http://www.foo.com'), ''], - [$this->createUri('foo/bar'), 'foo/bar'], - [$this->createUri('http://www.foo.com/foo bar'), '/foo%20bar'], - [$this->createUri('http://www.foo.com/foo%20bar'), '/foo%20bar'], - [$this->createUri('http://www.foo.com/foo%2fbar'), '/foo%2fbar'], + ['http://www.foo.com/', '/'], + ['http://www.foo.com', ''], + ['foo/bar', 'foo/bar'], + ['http://www.foo.com/foo bar', '/foo%20bar'], + ['http://www.foo.com/foo%20bar', '/foo%20bar'], + ['http://www.foo.com/foo%2fbar', '/foo%2fbar'], ]; } /** * @dataProvider getQueries */ - public function testQuery(UriInterface $uri, $expected) + public function testQuery(string $uri, string $expected) { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } - $this->assertSame($expected, $uri->getQuery()); + $this->assertSame($expected, $this->createUri($uri)->getQuery()); } - public function getQueries() + public static function getQueries() { return [ - [$this->createUri('http://www.foo.com'), ''], - [$this->createUri('http://www.foo.com?'), ''], - [$this->createUri('http://www.foo.com?foo=bar'), 'foo=bar'], - [$this->createUri('http://www.foo.com?foo=bar%26baz'), 'foo=bar%26baz'], - [$this->createUri('http://www.foo.com?foo=bar&baz=biz'), 'foo=bar&baz=biz'], + ['http://www.foo.com', ''], + ['http://www.foo.com?', ''], + ['http://www.foo.com?foo=bar', 'foo=bar'], + ['http://www.foo.com?foo=bar%26baz', 'foo=bar%26baz'], + ['http://www.foo.com?foo=bar&baz=biz', 'foo=bar&baz=biz'], ]; } /** * @dataProvider getFragments */ - public function testFragment(UriInterface $uri, $expected) + public function testFragment(string $uri, string $expected) { if (isset($this->skippedTests[__FUNCTION__])) { $this->markTestSkipped($this->skippedTests[__FUNCTION__]); } - $this->assertEquals($expected, $uri->getFragment()); + $this->assertEquals($expected, $this->createUri($uri)->getFragment()); } - public function getFragments() + public static function getFragments() { return [ - [$this->createUri('http://www.foo.com'), ''], - [$this->createUri('http://www.foo.com#'), ''], - [$this->createUri('http://www.foo.com#foo'), 'foo'], - [$this->createUri('http://www.foo.com#foo%20bar'), 'foo%20bar'], + ['http://www.foo.com', ''], + ['http://www.foo.com#', ''], + ['http://www.foo.com#foo', 'foo'], + ['http://www.foo.com#foo%20bar', 'foo%20bar'], ]; } diff --git a/tests/Guzzle/RequestTest.php b/tests/Guzzle/RequestTest.php index ca94250..a89abdc 100644 --- a/tests/Guzzle/RequestTest.php +++ b/tests/Guzzle/RequestTest.php @@ -16,7 +16,7 @@ public function createSubject() return new Request('GET', '/'); } - public function getInvalidHeaderArguments() + public static function getInvalidHeaderArguments() { $testCases = parent::getInvalidHeaderArguments(); diff --git a/tests/Guzzle/ResponseTest.php b/tests/Guzzle/ResponseTest.php index 8f051ef..e04017f 100644 --- a/tests/Guzzle/ResponseTest.php +++ b/tests/Guzzle/ResponseTest.php @@ -12,7 +12,7 @@ public function createSubject() return new Response(); } - public function getInvalidHeaderArguments() + public static function getInvalidHeaderArguments() { $testCases = parent::getInvalidHeaderArguments(); From 49564cfe1c0fb06215117b90a9e5b40448a053ef Mon Sep 17 00:00:00 2001 From: ignace nyamagana butera Date: Sat, 4 Mar 2023 12:59:40 +0100 Subject: [PATCH 2/6] Normalize class import and class alias --- src/BaseTest.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/BaseTest.php b/src/BaseTest.php index d2bf7a2..e2e6298 100644 --- a/src/BaseTest.php +++ b/src/BaseTest.php @@ -5,17 +5,17 @@ use GuzzleHttp\Psr7\Stream as GuzzleStream; use GuzzleHttp\Psr7\UploadedFile as GuzzleUploadedFile; use GuzzleHttp\Psr7\Uri as GuzzleUri; -use GuzzleHttp\Psr7\Utils; -use Http\Message\StreamFactory; -use Http\Message\UriFactory; +use GuzzleHttp\Psr7\Utils as GuzzleUtils; +use Http\Message\StreamFactory as HttpPlugStreamFactory; +use Http\Message\UriFactory as PsrUriFactory; use Laminas\Diactoros\Stream as ZendStream; use Laminas\Diactoros\Uri as ZendUri; use Laminas\Diactoros\UploadedFile as ZendUploadedFile; use PHPUnit\Framework\TestCase; -use Psr\Http\Message\StreamFactoryInterface; -use Psr\Http\Message\UploadedFileFactoryInterface; -use Psr\Http\Message\UriFactoryInterface; -use Psr\Http\Message\UriInterface; +use Psr\Http\Message\StreamFactoryInterface as PsrStreamFactoryInterface; +use Psr\Http\Message\UploadedFileFactoryInterface as PsrUploadedFileFactoryInterface; +use Psr\Http\Message\UriFactoryInterface as PsrUriFactoryInterface; +use Psr\Http\Message\UriInterface as PsrUriInterface; use Slim\Psr7\Uri as SlimUri; /** @@ -33,11 +33,11 @@ protected function buildUri($uri) if (defined('URI_FACTORY')) { $factoryClass = URI_FACTORY; $factory = new $factoryClass(); - if ($factory instanceof UriFactory) { + if ($factory instanceof PsrUriFactory) { return $factory->createUri($uri); } - if ($factory instanceof UriFactoryInterface) { - if ($uri instanceof UriInterface) { + if ($factory instanceof PsrUriFactoryInterface) { + if ($uri instanceof PsrUriInterface) { return $uri; } @@ -67,10 +67,10 @@ protected function buildStream($data) if (defined('STREAM_FACTORY')) { $factoryClass = STREAM_FACTORY; $factory = new $factoryClass(); - if ($factory instanceof StreamFactory) { + if ($factory instanceof HttpPlugStreamFactory) { return $factory->createStream($data); } - if ($factory instanceof StreamFactoryInterface) { + if ($factory instanceof PsrStreamFactoryInterface) { if (is_string($data)) { return $factory->createStream($data); } else { @@ -82,7 +82,7 @@ protected function buildStream($data) } if (class_exists(GuzzleStream::class)) { - return Utils::streamFor($data); + return GuzzleUtils::streamFor($data); } if (class_exists(ZendStream::class)) { @@ -97,7 +97,7 @@ protected function buildUploadableFile($data) if (defined('UPLOADED_FILE_FACTORY')) { $factoryClass = UPLOADED_FILE_FACTORY; $factory = new $factoryClass(); - if (!$factory instanceof UploadedFileFactoryInterface) { + if (!$factory instanceof PsrUploadedFileFactoryInterface) { throw new \RuntimeException('Constant "UPLOADED_FILE_FACTORY" must be a reference to a Psr\Http\Message\UploadedFileFactoryInterface'); } From eb7f2565c82a39b5d9cd0bba6efde5e6a5bede48 Mon Sep 17 00:00:00 2001 From: ignace nyamagana butera Date: Sun, 9 Apr 2023 00:20:03 +0200 Subject: [PATCH 3/6] Resolve conflict --- src/BaseTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/BaseTest.php b/src/BaseTest.php index 32f4032..0923823 100644 --- a/src/BaseTest.php +++ b/src/BaseTest.php @@ -17,6 +17,7 @@ use Slim\Psr7\Factory\UriFactory as SlimUriFactory; use Slim\Psr7\Factory\StreamFactory as SlimStreamFactory; use Slim\Psr7\Factory\UploadedFileFactory as SlimUploadedFileFactory; + /** * @author Tobias Nyholm */ From 4d0104ae020292a5fcee4c13c3d73e9c2e304684 Mon Sep 17 00:00:00 2001 From: ignace nyamagana butera Date: Sun, 14 May 2023 11:02:02 +0200 Subject: [PATCH 4/6] Remove PHP7.2 from github workflows --- .github/workflows/guzzle.yml | 2 +- .github/workflows/laminas-legacy.yml | 2 +- .github/workflows/nyholm.yml | 2 +- .github/workflows/ringcentral.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/guzzle.yml b/.github/workflows/guzzle.yml index 69a128a..15034e5 100644 --- a/.github/workflows/guzzle.yml +++ b/.github/workflows/guzzle.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ] + php: [ '7.3', '7.4', '8.0', '8.1', '8.2' ] uses: ./.github/workflows/integration.yml with: php: ${{ matrix.php }} diff --git a/.github/workflows/laminas-legacy.yml b/.github/workflows/laminas-legacy.yml index 3e75638..415c98f 100644 --- a/.github/workflows/laminas-legacy.yml +++ b/.github/workflows/laminas-legacy.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - php: [ '7.2', '7.3', '7.4' ] + php: [ '7.3', '7.4' ] uses: ./.github/workflows/integration.yml with: php: ${{ matrix.php }} diff --git a/.github/workflows/nyholm.yml b/.github/workflows/nyholm.yml index 199d7be..477263c 100644 --- a/.github/workflows/nyholm.yml +++ b/.github/workflows/nyholm.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ] + php: [ '7.3', '7.4', '8.0', '8.1', '8.2' ] uses: ./.github/workflows/integration.yml with: php: ${{ matrix.php }} diff --git a/.github/workflows/ringcentral.yml b/.github/workflows/ringcentral.yml index 12523ef..d50ccb1 100644 --- a/.github/workflows/ringcentral.yml +++ b/.github/workflows/ringcentral.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ] + php: [ '7.3', '7.4', '8.0', '8.1', '8.2' ] uses: ./.github/workflows/integration.yml with: php: ${{ matrix.php }} From f14ca3554d6c7244284ca39500abbfc975c93bcf Mon Sep 17 00:00:00 2001 From: ignace nyamagana butera Date: Sun, 14 May 2023 11:12:26 +0200 Subject: [PATCH 5/6] Migrate phpunit.xml.dist configuration file --- .gitattributes | 1 + .gitignore | 1 + phpunit.xml.dist | 51 ++++++++++++++++++++++-------------------------- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/.gitattributes b/.gitattributes index c47225a..bbfc162 100644 --- a/.gitattributes +++ b/.gitattributes @@ -13,3 +13,4 @@ /phpunit.xml.dist export-ignore /spec/ export-ignore /tests/ export-ignore +/.phpunit.cache/ export-ignore diff --git a/.gitignore b/.gitignore index 3a2f53d..77a33ca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /.tmp /.phpunit.result.cache +/.phpunit.cache /behat.yml /build/ /composer.lock diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5722406..f39deef 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,44 +1,39 @@ - - + + + + ./ + + + ./Tests + ./vendor + + ./tests/Guzzle/ - ./tests/RingCentral/ - - ./tests/Slim/ + ./tests/Slim/ - - ./tests/Laminas/ + ./tests/Laminas/ - - ./vendor/nyholm/psr7/tests/Integration/ + ./vendor/nyholm/psr7/tests/Integration/ - - - - ./ - - ./Tests - ./vendor - - - From abc024ed33e3472d4b6140f66ee20ed2a94240cc Mon Sep 17 00:00:00 2001 From: ignace nyamagana butera Date: Wed, 24 May 2023 08:08:38 +0200 Subject: [PATCH 6/6] Using FQN for PSR interfaces --- src/BaseTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/BaseTest.php b/src/BaseTest.php index 0923823..a3fc423 100644 --- a/src/BaseTest.php +++ b/src/BaseTest.php @@ -33,11 +33,11 @@ protected function buildUri($uri) if (defined('URI_FACTORY')) { $factoryClass = URI_FACTORY; $factory = new $factoryClass(); - if ($factory instanceof PsrUriFactory) { + if ($factory instanceof \Http\Message\UriFactory) { return $factory->createUri($uri); } - if ($factory instanceof PsrUriFactoryInterface) { - if ($uri instanceof PsrUriInterface) { + if ($factory instanceof \Psr\Http\Message\UriFactoryInterface) { + if ($uri instanceof \Psr\Http\Message\UriInterface) { return $uri; } @@ -79,10 +79,10 @@ protected function buildStream($data) if (defined('STREAM_FACTORY')) { $factoryClass = STREAM_FACTORY; $factory = new $factoryClass(); - if ($factory instanceof HttpPlugStreamFactory) { + if ($factory instanceof \Http\Message\StreamFactory) { return $factory->createStream($data); } - if ($factory instanceof PsrStreamFactoryInterface) { + if ($factory instanceof \Psr\Http\Message\StreamFactoryInterface) { if (is_string($data)) { return $factory->createStream($data); } @@ -127,7 +127,7 @@ protected function buildUploadableFile($data) if (defined('UPLOADED_FILE_FACTORY')) { $factoryClass = UPLOADED_FILE_FACTORY; $factory = new $factoryClass(); - if (!$factory instanceof PsrUploadedFileFactoryInterface) { + if (!$factory instanceof \Psr\Http\Message\UploadedFileFactoryInterface) { throw new \RuntimeException('Constant "UPLOADED_FILE_FACTORY" must be a reference to a Psr\Http\Message\UploadedFileFactoryInterface'); }