From e2d3906cb6c317223527a3559b1df248939787fb Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sun, 3 Mar 2024 18:40:23 +0100 Subject: [PATCH 01/10] make compatible with stream interface --- composer.json | 12 ++++++------ phpunit.xml.dist | 1 - src/ResponseReader.php | 6 ------ src/Stream.php | 32 +++++++++++++------------------- tests/SocketHttpClientTest.php | 6 ++---- 5 files changed, 21 insertions(+), 36 deletions(-) diff --git a/composer.json b/composer.json index 11542e4..22e45e0 100644 --- a/composer.json +++ b/composer.json @@ -9,17 +9,17 @@ } ], "require": { - "php": "^7.2 || ^8.0", - "nyholm/psr7": "^1.3", - "php-http/httplug": "^2.0", + "php": "^7.4 || ^8.0", + "nyholm/psr7": "^1.8.1", + "php-http/httplug": "^2.4", "psr/http-client": "^1.0", "symfony/options-resolver": "^2.6 || ^3.4 || ^4.4 || ^5.0 || ^6.0 || ^7.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^2.2 || ^3.0", + "friendsofphp/php-cs-fixer": "^3.51", "php-http/client-integration-tests": "^3.0", - "php-http/message": "^1.9", - "php-http/client-common": "^2.3", + "php-http/message": "^1.16", + "php-http/client-common": "^2.7", "phpunit/phpunit": "^8.5.23 || ~9.5" }, "provide": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 034d22e..f12146d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,7 +8,6 @@ tests/ - tests/SocketClientFeatureTest.php diff --git a/src/ResponseReader.php b/src/ResponseReader.php index 66431b0..d5beae6 100644 --- a/src/ResponseReader.php +++ b/src/ResponseReader.php @@ -4,7 +4,6 @@ use Http\Client\Socket\Exception\BrokenPipeException; use Http\Client\Socket\Exception\TimeoutException; -use Http\Message\ResponseFactory; use Nyholm\Psr7\Response; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -18,11 +17,6 @@ */ trait ResponseReader { - /** - * @var ResponseFactory For creating response - */ - protected $responseFactory; - /** * Read a response from a socket. * diff --git a/src/Stream.php b/src/Stream.php index 8d26ca0..0c059ca 100644 --- a/src/Stream.php +++ b/src/Stream.php @@ -61,7 +61,7 @@ public function __construct(RequestInterface $request, $socket, ?int $size = nul $this->request = $request; } - public function __toString() + public function __toString(): string { try { return $this->getContents(); @@ -70,7 +70,7 @@ public function __toString() } } - public function close() + public function close(): void { if ($this->isDetached || null === $this->socket) { throw new StreamException('Stream is detached'); @@ -93,12 +93,12 @@ public function detach() /** * @return int<0, max>|null */ - public function getSize() + public function getSize(): ?int { return $this->size; } - public function tell() + public function tell(): int { if ($this->isDetached || null === $this->socket) { throw new StreamException('Stream is detached'); @@ -111,7 +111,7 @@ public function tell() return $tell; } - public function eof() + public function eof(): bool { if ($this->isDetached || null === $this->socket) { throw new StreamException('Stream is detached'); @@ -120,38 +120,32 @@ public function eof() return feof($this->socket); } - public function isSeekable() + public function isSeekable(): bool { return false; } - /** - * @return void - */ - public function seek($offset, $whence = SEEK_SET) + public function seek($offset, $whence = SEEK_SET): void { throw new StreamException('This stream is not seekable'); } - /** - * @return void - */ - public function rewind() + public function rewind(): void { throw new StreamException('This stream is not seekable'); } - public function isWritable() + public function isWritable(): bool { return false; } - public function write($string) + public function write($string): int { throw new StreamException('This stream is not writable'); } - public function isReadable() + public function isReadable(): bool { return true; } @@ -159,7 +153,7 @@ public function isReadable() /** * @param int<0, max> $length */ - public function read($length) + public function read($length): string { if ($this->isDetached || null === $this->socket) { throw new StreamException('Stream is detached'); @@ -197,7 +191,7 @@ public function read($length) return $read; } - public function getContents() + public function getContents(): string { if ($this->isDetached || null === $this->socket) { throw new StreamException('Stream is detached'); diff --git a/tests/SocketHttpClientTest.php b/tests/SocketHttpClientTest.php index c3e5da2..657f2ff 100644 --- a/tests/SocketHttpClientTest.php +++ b/tests/SocketHttpClientTest.php @@ -6,15 +6,13 @@ use Http\Client\Socket\Client as SocketHttpClient; use Http\Client\Socket\Exception\NetworkException; use Http\Client\Socket\Exception\TimeoutException; -use Http\Message\MessageFactory\GuzzleMessageFactory; +use Nyholm\Psr7\Factory\Psr17Factory; class SocketHttpClientTest extends BaseTestCase { public function createClient($options = []) { - $messageFactory = new GuzzleMessageFactory(); - - return new HttpMethodsClient(new SocketHttpClient($options), $messageFactory); + return new HttpMethodsClient(new SocketHttpClient($options), new Psr17Factory()); } public function testTcpSocketDomain() From 1bb68e85b6be6567cc1ea145f8a2b145d9108cfe Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sat, 16 Mar 2024 14:12:29 +0100 Subject: [PATCH 02/10] adjust build matrix --- .github/workflows/ci.yml | 6 ++++-- composer.json | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b0e4f6a..1231aa2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,9 @@ name: CI on: push: branches: - - 2.x + - '[0-9]+.x' + - '[0-9]+.[0-9]+' + - '[0-9]+.[0-9]+.x' pull_request: jobs: @@ -91,7 +93,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: 7.4 + php-version: 8.3 tools: composer coverage: xdebug diff --git a/composer.json b/composer.json index 22e45e0..466c3b9 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ } ], "require": { - "php": "^7.4 || ^8.0", + "php": "^8.1", "nyholm/psr7": "^1.8.1", "php-http/httplug": "^2.4", "psr/http-client": "^1.0", From c84968190926fa68aeb258bc5f6850e9d1919fe5 Mon Sep 17 00:00:00 2001 From: Andrii Dembitskyi Date: Thu, 8 Aug 2024 00:30:05 +0300 Subject: [PATCH 03/10] :book: Fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 193ff9b..27be400 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ First launch the http server: $ ./vendor/bin/http_test_server > /dev/null 2>&1 & ``` -Then generate ssh certificates: +Then generate SSL certificates: ```bash $ composer gen-ssl From 61bb8f5fd07e64a6a7b921071545e07a6512b541 Mon Sep 17 00:00:00 2001 From: Andrii Dembitskyi Date: Thu, 8 Aug 2024 00:30:05 +0300 Subject: [PATCH 04/10] :package: Stick with working version of integration tests package TO BE REVERTED after [1] AND need to update min version for the tests package [1] https://github.com/php-http/client-integration-tests/pull/60 --- composer.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 466c3b9..60a68d0 100644 --- a/composer.json +++ b/composer.json @@ -17,10 +17,11 @@ }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.51", - "php-http/client-integration-tests": "^3.0", + "php-http/client-integration-tests": "3.0.1", "php-http/message": "^1.16", "php-http/client-common": "^2.7", - "phpunit/phpunit": "^8.5.23 || ~9.5" + "phpunit/phpunit": "^8.5.23 || ~9.5", + "php-http/message-factory": "^1.1" }, "provide": { "php-http/client-implementation": "1.0", From de0ef6b018fe2d02dcda885468566dd1e5bcd0ff Mon Sep 17 00:00:00 2001 From: Andrii Dembitskyi Date: Thu, 8 Aug 2024 00:30:05 +0300 Subject: [PATCH 05/10] :rotating_light: Explicitly specify what features of HTTP client is not supported by current implementation to avoid having failed tests --- tests/SocketClientFeatureTest.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/SocketClientFeatureTest.php b/tests/SocketClientFeatureTest.php index e6e698b..f1fe854 100644 --- a/tests/SocketClientFeatureTest.php +++ b/tests/SocketClientFeatureTest.php @@ -12,4 +12,29 @@ protected function createClient(): ClientInterface { return new SocketHttpClient(); } + + public function testAutoSetContentLength(): void + { + $this->markTestSkipped('Feature is unsupported'); + } + + public function testGzip(): void + { + $this->markTestSkipped('Feature is unsupported'); + } + + public function testDeflate(): void + { + $this->markTestSkipped('Feature is unsupported'); + } + + public function testChunked(): void + { + $this->markTestSkipped('Feature is unsupported'); + } + + public function testRedirect(): void + { + $this->markTestSkipped('Feature is unsupported'); + } } From 3fb6f4b9fa9182e6e04e6a70d670ff057d193066 Mon Sep 17 00:00:00 2001 From: Andrii Dembitskyi Date: Thu, 8 Aug 2024 00:33:54 +0300 Subject: [PATCH 06/10] :package: Explicitly declare compatibility versions for `psr/http-message` There is implementation for interface from this package --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 60a68d0..d965b23 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,7 @@ "nyholm/psr7": "^1.8.1", "php-http/httplug": "^2.4", "psr/http-client": "^1.0", + "psr/http-message": "^1.0 || ^2.0", "symfony/options-resolver": "^2.6 || ^3.4 || ^4.4 || ^5.0 || ^6.0 || ^7.0" }, "require-dev": { From 4510572c4016ca9fe87dc0f6189c5da6ad7bce65 Mon Sep 17 00:00:00 2001 From: Andrii Dembitskyi Date: Thu, 8 Aug 2024 00:38:57 +0300 Subject: [PATCH 07/10] :book: Add changelog entry about fixed compatibility with `psr/http-message` v2 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b030fcb..224b22c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## 3.0.0 + + * Fixed compatibility with `psr/http-message` v2 + ## 2.2.0 * Allow installation with Symfony 7 From eebe6b05368e19824ce9c9da180f95c5267fb1dc Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sun, 1 Sep 2024 12:33:26 +0200 Subject: [PATCH 08/10] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d965b23..0689754 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.51", - "php-http/client-integration-tests": "3.0.1", + "php-http/client-integration-tests": "^3.1.1", "php-http/message": "^1.16", "php-http/client-common": "^2.7", "phpunit/phpunit": "^8.5.23 || ~9.5", From 10a13f17d2cfc746f4cceee956d8c3f70686d841 Mon Sep 17 00:00:00 2001 From: Andrii Date: Sun, 1 Sep 2024 14:39:38 +0300 Subject: [PATCH 09/10] :package: `fread` requires to pass only `int<1, max>` - early return empty string in case of `0` length --- src/Stream.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Stream.php b/src/Stream.php index 0c059ca..afe6dd6 100644 --- a/src/Stream.php +++ b/src/Stream.php @@ -155,9 +155,14 @@ public function isReadable(): bool */ public function read($length): string { + if (0 === $length) { + return ''; + } + if ($this->isDetached || null === $this->socket) { throw new StreamException('Stream is detached'); } + if (null === $this->getSize()) { $read = fread($this->socket, $length); if (false === $read) { From 5a1abddd59746dba1b61042de25ce57ca04214b7 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sun, 1 Sep 2024 13:44:18 +0200 Subject: [PATCH 10/10] Apply suggestions from code review --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 224b22c..b766856 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ # Change Log -## 3.0.0 +## 2.3.0 * Fixed compatibility with `psr/http-message` v2 + * The `Http\Client\Socket\Stream` has BC breaks if you extended it. It is not meant to be extended, declaring it as `@internal` now. ## 2.2.0