From 888d172d251fd3a0bc5c9ea2d73930abafc7088d Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Tue, 23 May 2023 17:34:51 +0300 Subject: [PATCH 1/4] Add httpsoft tests --- .github/workflows/httpsoft.yml | 19 +++++++++++++++++++ README.md | 2 +- composer.json | 1 + phpunit.xml.dist | 4 ++++ tests/HttpSoft/RequestTest.php | 16 ++++++++++++++++ tests/HttpSoft/ResponseTest.php | 16 ++++++++++++++++ tests/HttpSoft/ServerRequestTest.php | 14 ++++++++++++++ tests/HttpSoft/StreamTest.php | 19 +++++++++++++++++++ tests/HttpSoft/UploadedFileTest.php | 18 ++++++++++++++++++ tests/HttpSoft/UriTest.php | 14 ++++++++++++++ 10 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/httpsoft.yml create mode 100644 tests/HttpSoft/RequestTest.php create mode 100644 tests/HttpSoft/ResponseTest.php create mode 100644 tests/HttpSoft/ServerRequestTest.php create mode 100644 tests/HttpSoft/StreamTest.php create mode 100644 tests/HttpSoft/UploadedFileTest.php create mode 100644 tests/HttpSoft/UriTest.php diff --git a/.github/workflows/httpsoft.yml b/.github/workflows/httpsoft.yml new file mode 100644 index 0000000..016f865 --- /dev/null +++ b/.github/workflows/httpsoft.yml @@ -0,0 +1,19 @@ +name: HttpSoft + +on: + push: + branches: + - '*.x' + pull_request: + +jobs: + latest: + strategy: + fail-fast: false + matrix: + php: [ '7.4', '8.0', '8.1', '8.2' ] + uses: ./.github/workflows/integration.yml + with: + php: ${{ matrix.php }} + suite: HttpSoft + package: httpsoft/http-message diff --git a/README.md b/README.md index 67e9894..90790a9 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ | Slim | [![Slim](https://github.com/php-http/psr7-integration-tests/actions/workflows/slim.yml/badge.svg)](https://github.com/php-http/psr7-integration-tests/actions/workflows/slim.yml) | | Nyholm | [![Nyholm](https://github.com/php-http/psr7-integration-tests/actions/workflows/nyholm.yml/badge.svg)](https://github.com/php-http/psr7-integration-tests/actions/workflows/nyholm.yml) | | RingCentral | [![RingCentral](https://github.com/php-http/psr7-integration-tests/actions/workflows/ringcentral.yml/badge.svg)](https://github.com/php-http/psr7-integration-tests/actions/workflows/ringcentral.yml) | - +| HttpSoft | [![HttpSoft](https://github.com/php-http/psr7-integration-tests/actions/workflows/httpsoft.yml/badge.svg)](https://github.com/php-http/psr7-integration-tests/actions/workflows/httpsoft.yml) | ## Install diff --git a/composer.json b/composer.json index eea6c4b..02b5705 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,7 @@ }, "require-dev": { "guzzlehttp/psr7": "^1.7 || ^2.0", + "httpsoft/http-message": "^1.1", "laminas/laminas-diactoros": "^2.1", "nyholm/psr7": "^1.0", "ringcentral/psr7": "^1.2", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5722406..296fa5a 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -30,6 +30,10 @@ ./vendor/nyholm/psr7/tests/Integration/ + + + ./tests/HttpSoft/ + diff --git a/tests/HttpSoft/RequestTest.php b/tests/HttpSoft/RequestTest.php new file mode 100644 index 0000000..f6e7aaa --- /dev/null +++ b/tests/HttpSoft/RequestTest.php @@ -0,0 +1,16 @@ +write('foobar'); + + return new UploadedFile($stream, $stream->getSize(), UPLOAD_ERR_OK); + } +} diff --git a/tests/HttpSoft/UriTest.php b/tests/HttpSoft/UriTest.php new file mode 100644 index 0000000..f1489e4 --- /dev/null +++ b/tests/HttpSoft/UriTest.php @@ -0,0 +1,14 @@ + Date: Tue, 23 May 2023 17:42:10 +0300 Subject: [PATCH 2/4] fix --- tests/HttpSoft/RequestTest.php | 6 ++++++ tests/HttpSoft/ServerRequestTest.php | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/tests/HttpSoft/RequestTest.php b/tests/HttpSoft/RequestTest.php index f6e7aaa..79046e2 100644 --- a/tests/HttpSoft/RequestTest.php +++ b/tests/HttpSoft/RequestTest.php @@ -6,6 +6,7 @@ use Http\Psr7Test\RequestIntegrationTest; use HttpSoft\Message\Request; +use HttpSoft\Message\Uri; class RequestTest extends RequestIntegrationTest { @@ -13,4 +14,9 @@ public function createSubject() { return new Request('GET', '/'); } + + protected function buildUri($uri) + { + return new Uri($uri); + } } diff --git a/tests/HttpSoft/ServerRequestTest.php b/tests/HttpSoft/ServerRequestTest.php index 2f6e1e4..eeee761 100644 --- a/tests/HttpSoft/ServerRequestTest.php +++ b/tests/HttpSoft/ServerRequestTest.php @@ -4,6 +4,7 @@ use Http\Psr7Test\ServerRequestIntegrationTest; use HttpSoft\Message\ServerRequest; +use HttpSoft\Message\Uri; class ServerRequestTest extends ServerRequestIntegrationTest { @@ -11,4 +12,9 @@ public function createSubject() { return new ServerRequest($_SERVER); } + + protected function buildUri($uri) + { + return new Uri($uri); + } } From 42366c9ddebf81327fea923bea59a40fa3b97a23 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Wed, 24 May 2023 22:23:22 +0300 Subject: [PATCH 3/4] Use package tests --- phpunit.xml.dist | 2 +- src/BaseTest.php | 5 +++++ tests/HttpSoft/RequestTest.php | 22 ---------------------- tests/HttpSoft/ResponseTest.php | 16 ---------------- tests/HttpSoft/ServerRequestTest.php | 20 -------------------- tests/HttpSoft/StreamTest.php | 19 ------------------- tests/HttpSoft/UploadedFileTest.php | 18 ------------------ tests/HttpSoft/UriTest.php | 14 -------------- 8 files changed, 6 insertions(+), 110 deletions(-) delete mode 100644 tests/HttpSoft/RequestTest.php delete mode 100644 tests/HttpSoft/ResponseTest.php delete mode 100644 tests/HttpSoft/ServerRequestTest.php delete mode 100644 tests/HttpSoft/StreamTest.php delete mode 100644 tests/HttpSoft/UploadedFileTest.php delete mode 100644 tests/HttpSoft/UriTest.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 296fa5a..1f1884c 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -32,7 +32,7 @@ - ./tests/HttpSoft/ + ./vendor/httpsoft/http-message/tests/Integration/ diff --git a/src/BaseTest.php b/src/BaseTest.php index f467bba..cf63673 100644 --- a/src/BaseTest.php +++ b/src/BaseTest.php @@ -5,6 +5,7 @@ use GuzzleHttp\Psr7\Stream as GuzzleStream; use GuzzleHttp\Psr7\UploadedFile as GuzzleUploadedFile; use GuzzleHttp\Psr7\Uri as GuzzleUri; +use HttpSoft\Message\Uri as HttpSoftUri; use Laminas\Diactoros\StreamFactory as LaminasStreamFactory; use Laminas\Diactoros\Uri as LaminasUri; use Laminas\Diactoros\UploadedFile as LaminasUploadedFile; @@ -47,6 +48,10 @@ protected function buildUri($uri) throw new \RuntimeException('Constant "URI_FACTORY" must be a reference to a Http\Message\UriFactory or \Psr\Http\Message\UriFactoryInterface'); } + if (class_exists(HttpSoftUri::class)) { + return new HttpSoftUri($uri); + } + if (class_exists(GuzzleUri::class)) { return new GuzzleUri($uri); } diff --git a/tests/HttpSoft/RequestTest.php b/tests/HttpSoft/RequestTest.php deleted file mode 100644 index 79046e2..0000000 --- a/tests/HttpSoft/RequestTest.php +++ /dev/null @@ -1,22 +0,0 @@ -write('foobar'); - - return new UploadedFile($stream, $stream->getSize(), UPLOAD_ERR_OK); - } -} diff --git a/tests/HttpSoft/UriTest.php b/tests/HttpSoft/UriTest.php deleted file mode 100644 index f1489e4..0000000 --- a/tests/HttpSoft/UriTest.php +++ /dev/null @@ -1,14 +0,0 @@ - Date: Thu, 25 May 2023 17:06:45 +0300 Subject: [PATCH 4/4] Fix --- .github/workflows/integration.yml | 2 +- src/BaseTest.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 605523c..a760a4c 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -32,7 +32,7 @@ jobs: # then we install the dependencies # and finally require the implementation to test with source flag (to get integration test cases that might be excluded in git-attributes) run: | - composer remove --dev guzzlehttp/psr7 laminas/laminas-diactoros nyholm/psr7 ringcentral/psr7 slim/psr7 --no-update + composer remove --dev guzzlehttp/psr7 laminas/laminas-diactoros nyholm/psr7 ringcentral/psr7 slim/psr7 httpsoft/http-message --no-update composer require ${{ inputs.package }} --no-interaction --no-progress --prefer-source - name: Execute tests diff --git a/src/BaseTest.php b/src/BaseTest.php index cf63673..aeeb8c4 100644 --- a/src/BaseTest.php +++ b/src/BaseTest.php @@ -5,6 +5,8 @@ use GuzzleHttp\Psr7\Stream as GuzzleStream; use GuzzleHttp\Psr7\UploadedFile as GuzzleUploadedFile; use GuzzleHttp\Psr7\Uri as GuzzleUri; +use HttpSoft\Message\StreamFactory as HttpSoftStreamFactory; +use HttpSoft\Message\UploadedFile as HttpSoftUploadedFile; use HttpSoft\Message\Uri as HttpSoftUri; use Laminas\Diactoros\StreamFactory as LaminasStreamFactory; use Laminas\Diactoros\Uri as LaminasUri; @@ -103,6 +105,9 @@ protected function buildStream($data) } $factory = null; + if (class_exists(HttpSoftStreamFactory::class)) { + $factory = new HttpSoftStreamFactory(); + } if (class_exists(LaminasStreamFactory::class)) { $factory = new LaminasStreamFactory(); } @@ -141,6 +146,10 @@ protected function buildUploadableFile($data) return $factory->createUploadedFile($stream); } + if (class_exists(HttpSoftUploadedFile::class)) { + return new HttpSoftUploadedFile($data, strlen($data), 0); + } + if (class_exists(GuzzleUploadedFile::class)) { return new GuzzleUploadedFile($data, strlen($data), 0); }