From 4fcceb3429393267ae117743801f49d69d6ca213 Mon Sep 17 00:00:00 2001 From: Remon van de Kamp Date: Fri, 23 Feb 2024 10:49:09 +0100 Subject: [PATCH] (Re-)add support for psr/http-message version 1.0 --- .github/workflows/build.yml | 7 ++----- composer.json | 6 +++--- src/MailhogClient.php | 13 +++++++++++-- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4313121..ce3b0e0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,8 +4,6 @@ on: push: branches: [master] pull_request: - schedule: - - cron: '39 2 * * 0' jobs: tests: @@ -19,12 +17,12 @@ jobs: ports: - 2025:2025 - 9025:9025 - runs-on: ubuntu-18.04 + runs-on: ubuntu-22.04 name: Test strategy: fail-fast: false matrix: - php: ["7.2", "7.3", "7.4", "8.0"] + php: ["7.2", "7.3", "7.4", "8.0", "8.1", "8.2", "8.3"] composer-flags: ["", "--prefer-lowest"] env: @@ -43,4 +41,3 @@ jobs: - name: Run tests run: make test - diff --git a/composer.json b/composer.json index eab4b6e..5f84878 100644 --- a/composer.json +++ b/composer.json @@ -25,13 +25,13 @@ "ext-json": "*", "ext-iconv": "*", "php-http/client-implementation": "^1.0", - "php-http/httplug": "^1.0|^2.0", - "psr/http-message": "^2.0", + "php-http/httplug": "^1.0 || ^2.0", + "psr/http-message": "^1.0 || ^2.0", "psr/http-factory": "^1.0" }, "require-dev": { "phpmd/phpmd": "^2.9.1", - "phpunit/phpunit": "^8.0", + "phpunit/phpunit": "^8.0 || ^9.0 || ^10.0", "php-http/curl-client": "^2.0", "phpstan/phpstan": "^0.12.64", "pdepend/pdepend": "^2.5", diff --git a/src/MailhogClient.php b/src/MailhogClient.php index 79375bd..af31ff0 100644 --- a/src/MailhogClient.php +++ b/src/MailhogClient.php @@ -7,6 +7,7 @@ use Generator; use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestFactoryInterface; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\StreamFactoryInterface; use rpkamp\Mailhog\Message\Message; use rpkamp\Mailhog\Message\MessageFactory; @@ -14,6 +15,7 @@ use RuntimeException; use function array_filter; +use function assert; use function count; use function iterator_to_array; use function json_decode; @@ -178,9 +180,16 @@ public function releaseMessage(string $messageId, string $host, int $port, strin $request = $this->requestFactory->createRequest( 'POST', sprintf('%s/api/v1/messages/%s/release', $this->baseUri, $messageId) - ); + )->withBody($this->streamFactory->createStream($body)); + + /** + * Help PHPStan see that this is actually a RequestInterface. withBody is a method + * on MessageInterface and has return type MessageInterface in version 1.0 of psr/http-message. + * This has been fixed in version 2.0 of psr/http-message where the return type is `static`. + */ + assert($request instanceof RequestInterface); - $this->httpClient->sendRequest($request->withBody($this->streamFactory->createStream($body))); + $this->httpClient->sendRequest($request); } public function getMessageById(string $messageId): Message