Skip to content

Commit

Permalink
(Re-)add support for psr/http-message version 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rpkamp committed Feb 23, 2024
1 parent 18c3af6 commit 4fcceb3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ on:
push:
branches: [master]
pull_request:
schedule:
- cron: '39 2 * * 0'

jobs:
tests:
Expand All @@ -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:
Expand All @@ -43,4 +41,3 @@ jobs:

- name: Run tests
run: make test

6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 11 additions & 2 deletions src/MailhogClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
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;
use rpkamp\Mailhog\Specification\Specification;
use RuntimeException;

use function array_filter;
use function assert;
use function count;
use function iterator_to_array;
use function json_decode;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4fcceb3

Please sign in to comment.