From 11324bb97c35fa52ba7858d8e5391069eadf2e9e Mon Sep 17 00:00:00 2001 From: Chromec Petr Date: Wed, 6 Mar 2024 14:04:31 +0100 Subject: [PATCH] Drop support for php 8.1 and uUpdate dependencies --- .github/workflows/tests.yaml | 6 ++--- CHANGELOG.md | 2 ++ composer.json | 12 ++++----- phpstan.neon | 6 ----- phpunit.xml.dist | 19 +++++-------- tests/AbstractHttpTestCase.php | 8 +++--- .../HttpMessageResponseDecoderTest.php | 18 ++++++------- tests/Decoder/StreamResponseDecoderTest.php | 18 ++++++------- tests/Formatter/HttpProfilerFormatterTest.php | 27 +++++++++---------- tests/Handler/HttpQueryHandlerTest.php | 13 +++------ tests/Handler/HttpSendCommandHandlerTest.php | 17 ++++-------- 11 files changed, 63 insertions(+), 83 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 4317b80..4907339 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -12,10 +12,10 @@ jobs: strategy: matrix: - php-version: ['8.1'] + php-version: ['8.2', '8.3'] dependencies: [''] include: - - { php-version: '8.1', dependencies: '--prefer-lowest --prefer-stable' } + - { php-version: '8.2', dependencies: '--prefer-lowest --prefer-stable' } name: Unit tests - PHP ${{ matrix.dependencies }} @@ -65,7 +65,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.2' extensions: json, mbstring - name: Install dependencies diff --git a/CHANGELOG.md b/CHANGELOG.md index ccb44a8..2953290 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ ## Unreleased +- Drop support for php 8.1 +- Update dependencies ## 3.0.0 - 2022-04-27 - Require php 8.1 diff --git a/composer.json b/composer.json index 392f174..722c26e 100644 --- a/composer.json +++ b/composer.json @@ -4,14 +4,14 @@ "license": "MIT", "type": "library", "require": { - "php": "^8.1", + "php": "^8.2", "ext-json": "*", "ext-mbstring": "*", "fig/http-message-util": "^1.1", - "lmc/cqrs-types": "^3.0", + "lmc/cqrs-types": "^3.2", "psr/http-client": "^1.0", "psr/http-factory": "^1.0", - "psr/http-message": "^1.0" + "psr/http-message": "^1.0 || ^2.0" }, "require-dev": { "ergebnis/composer-normalize": "^2.5", @@ -22,7 +22,7 @@ "phpstan/extension-installer": "^1.1", "phpstan/phpstan": "^1.4", "phpstan/phpstan-phpunit": "^1.0", - "phpunit/phpunit": "^9.5" + "phpunit/phpunit": "^11.0.4" }, "autoload": { "psr-4": { @@ -36,9 +36,9 @@ }, "config": { "allow-plugins": { - "phpstan/extension-installer": true, + "dealerdirect/phpcodesniffer-composer-installer": true, "ergebnis/composer-normalize": true, - "dealerdirect/phpcodesniffer-composer-installer": true + "phpstan/extension-installer": true }, "sort-packages": true }, diff --git a/phpstan.neon b/phpstan.neon index 3ff2c54..4ad7760 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -7,9 +7,3 @@ parameters: - tests/ reportUnmatchedIgnoredErrors: true - - ignoreErrors: - - - message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#" - count: 1 - path: src/Command/AbstractHttpPostCommand.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a0aed18..beb0fc5 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,34 +1,29 @@ - - + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd" colors="true" + bootstrap="vendor/autoload.php"> - - src - - - tests/ - + + + src + + diff --git a/tests/AbstractHttpTestCase.php b/tests/AbstractHttpTestCase.php index f44c8f0..43e01f1 100644 --- a/tests/AbstractHttpTestCase.php +++ b/tests/AbstractHttpTestCase.php @@ -2,6 +2,8 @@ namespace Lmc\Cqrs\Http; +use Nyholm\Psr7\Uri; +use PHPUnit\Framework\Attributes\Before; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Http\Client\ClientInterface; @@ -17,13 +19,13 @@ abstract class AbstractHttpTestCase extends TestCase /** @var RequestFactoryInterface|MockObject */ protected RequestFactoryInterface $requestFactory; - /** @before */ + #[Before] public function setUpClient(): void { $this->client = $this->createMock(ClientInterface::class); } - /** @before */ + #[Before] public function setUpRequestFactory(): void { $this->requestFactory = $this->createMock(RequestFactoryInterface::class); @@ -36,7 +38,7 @@ protected function prepareRequest(string $url, string $method): RequestInterface $request->expects($this->any()) ->method('getUri') - ->willReturn($url); + ->willReturn(new Uri($url)); $request->expects($this->any()) ->method('getMethod') diff --git a/tests/Decoder/HttpMessageResponseDecoderTest.php b/tests/Decoder/HttpMessageResponseDecoderTest.php index 0619ae4..91bb40e 100644 --- a/tests/Decoder/HttpMessageResponseDecoderTest.php +++ b/tests/Decoder/HttpMessageResponseDecoderTest.php @@ -4,6 +4,8 @@ use GuzzleHttp\Psr7\Utils; use Lmc\Cqrs\Http\AbstractHttpTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; class HttpMessageResponseDecoderTest extends AbstractHttpTestCase { @@ -14,10 +16,8 @@ protected function setUp(): void $this->decoder = new HttpMessageResponseDecoder(); } - /** - * @dataProvider provideMessage - * @test - */ + #[Test] + #[DataProvider('provideMessage')] public function shouldDecodeNyholmMessage(mixed $message, bool $isSupported, mixed $expected): void { $decoded = $this->decoder->decode($message); @@ -26,7 +26,7 @@ public function shouldDecodeNyholmMessage(mixed $message, bool $isSupported, mix $this->assertEquals($expected, $decoded); } - public function provideMessage(): iterable + public static function provideMessage(): iterable { yield 'not a message' => [ $obj = new \stdClass(), @@ -34,11 +34,11 @@ public function provideMessage(): iterable $obj, ]; - yield from $this->provideNyholmMessage(); - yield from $this->provideGuzzleMessage(); + yield from self::provideNyholmMessage(); + yield from self::provideGuzzleMessage(); } - public function provideNyholmMessage(): iterable + public static function provideNyholmMessage(): iterable { yield 'request Nyholm with body' => [ (new \Nyholm\Psr7\Request('post', 'url'))->withBody($stream = \Nyholm\Psr7\Stream::create('body')), @@ -59,7 +59,7 @@ public function provideNyholmMessage(): iterable ]; } - public function provideGuzzleMessage(): iterable + public static function provideGuzzleMessage(): iterable { yield 'Guzzle request with body' => [ (new \GuzzleHttp\Psr7\Request('post', 'url'))->withBody($stream = Utils::streamFor('body')), diff --git a/tests/Decoder/StreamResponseDecoderTest.php b/tests/Decoder/StreamResponseDecoderTest.php index 2e5eb31..faf2ebb 100644 --- a/tests/Decoder/StreamResponseDecoderTest.php +++ b/tests/Decoder/StreamResponseDecoderTest.php @@ -4,6 +4,8 @@ use GuzzleHttp\Psr7\Utils; use Lmc\Cqrs\Http\AbstractHttpTestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; class StreamResponseDecoderTest extends AbstractHttpTestCase { @@ -14,10 +16,8 @@ protected function setUp(): void $this->decoder = new StreamResponseDecoder(); } - /** - * @dataProvider provideMessage - * @test - */ + #[Test] + #[DataProvider('provideMessage')] public function shouldDecodeNyholmMessage(mixed $message, bool $isSupported, mixed $expected): void { $decoded = $this->decoder->decode($message); @@ -26,7 +26,7 @@ public function shouldDecodeNyholmMessage(mixed $message, bool $isSupported, mix $this->assertEquals($expected, $decoded); } - public function provideMessage(): iterable + public static function provideMessage(): iterable { yield 'not a stream' => [ $obj = new \stdClass(), @@ -34,11 +34,11 @@ public function provideMessage(): iterable $obj, ]; - yield from $this->provideNyholmMessage(); - yield from $this->provideGuzzleMessage(); + yield from self::provideNyholmMessage(); + yield from self::provideGuzzleMessage(); } - public function provideNyholmMessage(): iterable + public static function provideNyholmMessage(): iterable { yield 'Nyholm stream' => [ \Nyholm\Psr7\Stream::create('body'), @@ -47,7 +47,7 @@ public function provideNyholmMessage(): iterable ]; } - public function provideGuzzleMessage(): iterable + public static function provideGuzzleMessage(): iterable { yield 'Guzzle stream' => [ Utils::streamFor('body'), diff --git a/tests/Formatter/HttpProfilerFormatterTest.php b/tests/Formatter/HttpProfilerFormatterTest.php index e1c0892..ae50a85 100644 --- a/tests/Formatter/HttpProfilerFormatterTest.php +++ b/tests/Formatter/HttpProfilerFormatterTest.php @@ -6,6 +6,8 @@ use Lmc\Cqrs\Http\AbstractHttpTestCase; use Lmc\Cqrs\Types\ValueObject\FormattedValue; use Lmc\Cqrs\Types\ValueObject\ProfilerItem; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; class HttpProfilerFormatterTest extends AbstractHttpTestCase { @@ -16,11 +18,8 @@ protected function setUp(): void $this->formatter = new HttpProfilerFormatter(); } - /** - * @dataProvider provideProfilerItem - * - * @test - */ + #[Test] + #[DataProvider('provideProfilerItem')] public function shouldProfileItem(ProfilerItem $item, ProfilerItem $expected): void { $formatted = $this->formatter->formatItem($item); @@ -28,21 +27,21 @@ public function shouldProfileItem(ProfilerItem $item, ProfilerItem $expected): v $this->assertEquals($expected, $formatted); } - public function provideProfilerItem(): iterable + public static function provideProfilerItem(): iterable { yield 'without anything to format' => [ new ProfilerItem('id', null, 'test'), new ProfilerItem('id', null, 'test'), ]; - yield from $this->provideNyholmItems(); - yield from $this->provideNyholmAdditioanlItems(); + yield from self::provideNyholmItems(); + yield from self::provideNyholmAdditioanlItems(); - yield from $this->provideGuzzleItems(); - yield from $this->provideGuzzleAdditionalItems(); + yield from self::provideGuzzleItems(); + yield from self::provideGuzzleAdditionalItems(); } - public function provideNyholmItems(): iterable + public static function provideNyholmItems(): iterable { yield 'with Nyholm request with body' => [ new ProfilerItem( @@ -132,7 +131,7 @@ public function provideNyholmItems(): iterable ]; } - public function provideNyholmAdditioanlItems(): iterable + public static function provideNyholmAdditioanlItems(): iterable { yield 'with additional Nyholm request with body' => [ new ProfilerItem( @@ -225,7 +224,7 @@ public function provideNyholmAdditioanlItems(): iterable ]; } - public function provideGuzzleItems(): iterable + public static function provideGuzzleItems(): iterable { yield 'with Guzzle request with body' => [ new ProfilerItem( @@ -315,7 +314,7 @@ public function provideGuzzleItems(): iterable ]; } - public function provideGuzzleAdditionalItems(): iterable + public static function provideGuzzleAdditionalItems(): iterable { yield 'with additional Guzzle request with body' => [ new ProfilerItem( diff --git a/tests/Handler/HttpQueryHandlerTest.php b/tests/Handler/HttpQueryHandlerTest.php index fd35594..70431fb 100644 --- a/tests/Handler/HttpQueryHandlerTest.php +++ b/tests/Handler/HttpQueryHandlerTest.php @@ -9,6 +9,7 @@ use Lmc\Cqrs\Types\Exception\CqrsExceptionInterface; use Lmc\Cqrs\Types\ValueObject\OnErrorCallback; use Lmc\Cqrs\Types\ValueObject\OnSuccessCallback; +use PHPUnit\Framework\Attributes\Test; use Psr\Http\Message\ResponseInterface; class HttpQueryHandlerTest extends AbstractHttpTestCase @@ -20,9 +21,7 @@ protected function setUp(): void $this->httpQueryHandler = new HttpQueryHandler($this->client); } - /** - * @test - */ + #[Test] public function shouldFetchHttpQuery(): void { $uri = 'some-url'; @@ -45,9 +44,7 @@ public function shouldFetchHttpQuery(): void ); } - /** - * @test - */ + #[Test] public function shouldFetchHttpQueryAsErrorWithBadRequest(): void { $uri = 'some-url'; @@ -76,9 +73,7 @@ public function shouldFetchHttpQueryAsErrorWithBadRequest(): void ); } - /** - * @test - */ + #[Test] public function shouldFetchHttpQueryAsErrorWithServerError(): void { $uri = 'some-url'; diff --git a/tests/Handler/HttpSendCommandHandlerTest.php b/tests/Handler/HttpSendCommandHandlerTest.php index 18af340..f4a4dce 100644 --- a/tests/Handler/HttpSendCommandHandlerTest.php +++ b/tests/Handler/HttpSendCommandHandlerTest.php @@ -10,6 +10,7 @@ use Lmc\Cqrs\Types\Exception\CqrsExceptionInterface; use Lmc\Cqrs\Types\ValueObject\OnErrorCallback; use Lmc\Cqrs\Types\ValueObject\OnSuccessCallback; +use PHPUnit\Framework\Attributes\Test; use Psr\Http\Message\ResponseInterface; class HttpSendCommandHandlerTest extends AbstractHttpTestCase @@ -21,9 +22,7 @@ protected function setUp(): void $this->httpSendCommandHandler = new HttpSendCommandHandler($this->client); } - /** - * @test - */ + #[Test] public function shouldSendPostCommand(): void { $uri = 'some-url'; @@ -49,9 +48,7 @@ public function shouldSendPostCommand(): void ); } - /** - * @test - */ + #[Test] public function shouldSendPutCommand(): void { $uri = 'some-url'; @@ -74,9 +71,7 @@ public function shouldSendPutCommand(): void ); } - /** - * @test - */ + #[Test] public function shouldSendPutCommandAsErrorWithBadRequest(): void { $uri = 'some-url'; @@ -105,9 +100,7 @@ public function shouldSendPutCommandAsErrorWithBadRequest(): void ); } - /** - * @test - */ + #[Test] public function shouldSendPutCommandAsErrorWithServerError(): void { $uri = 'some-url';