Skip to content

Commit

Permalink
Merge pull request #59 from rpkamp/psr-http-message-1
Browse files Browse the repository at this point in the history
(Re-)add support for psr/http-message version 1.0
  • Loading branch information
rpkamp authored Feb 23, 2024
2 parents 18c3af6 + 25ca2af commit 1f6e713
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
8 changes: 2 additions & 6 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,28 +17,26 @@ 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"]
composer-flags: ["", "--prefer-lowest"]

env:
COMPOSER_ROOT_VERSION: dev-master

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
coverage: pcov

- name: Install dependencies
run: composer update ${{ matrix.composer-flags }}

- name: Run tests
run: make test

6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ code-style: phpmd phpcs
phpmd:
vendor/bin/phpmd src/ xml phpmd.xml --suffixes php

# Check code adheres to PSR-2
# Check if code adheres to PSR-2
phpcs:
vendor/bin/phpcs

# Run unit tests
unit-tests:
ifeq ($(CI),true)
vendor/bin/phpunit --testdox -v --coverage-clover=coverage.xml
vendor/bin/phpunit --coverage-clover=coverage.xml
else
vendor/bin/phpunit --testdox -v
vendor/bin/phpunit
endif

phpstan:
Expand Down
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 1f6e713

Please sign in to comment.