diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4c3515a..c826368 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,7 +33,7 @@ jobs: tools: composer:v2 - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Download dependencies run: | diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index f9635cd..75f222d 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -13,7 +13,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: PHP-CS-Fixer uses: docker://oskarstark/php-cs-fixer-ga:2.16.4 diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d08045..030cae3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [3.1.2] - 2025-11-11 + +- Allow PHPUnit > 9 +- Deprecate PhpUnitBackwardCompatibleTrait + ## [3.1.1] - 2024-09-01 - Switched to `httpbin.org` for tests now that its fixed. (Reverts [#56](https://github.com/php-http/client-integration-tests/pull/56)) diff --git a/composer.json b/composer.json index 25ea7b6..784d11f 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ ], "require": { "php": "^7.4 || ^8.0", - "phpunit/phpunit": "^9.6.17", + "phpunit/phpunit": "^9.6.17 || ^10.0 || ^11.0 || ^12.0", "php-http/message": "^1.0 || ^2.0", "php-http/message-factory": "^1.0", "guzzlehttp/psr7": "^1.9 || ^2.0", diff --git a/src/HttpAsyncClientTest.php b/src/HttpAsyncClientTest.php index 0f13c05..1301ff6 100644 --- a/src/HttpAsyncClientTest.php +++ b/src/HttpAsyncClientTest.php @@ -3,6 +3,8 @@ namespace Http\Client\Tests; use Http\Client\HttpAsyncClient; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; abstract class HttpAsyncClientTest extends HttpBaseTest { @@ -33,8 +35,8 @@ public function testSuccessiveCallMustUseResponseInterface() { $request = self::$messageFactory->createRequest( 'GET', - $this->getUri(), - $this->defaultHeaders + self::getUri(), + self::$defaultHeaders ); $promise = $this->httpAsyncClient->sendAsyncRequest($request); @@ -61,7 +63,7 @@ public function testSuccessiveInvalidCallMustUseException() $request = self::$messageFactory->createRequest( 'GET', $this->getInvalidUri(), - $this->defaultHeaders + self::$defaultHeaders ); $promise = $this->httpAsyncClient->sendAsyncRequest($request); @@ -90,6 +92,8 @@ public function testSuccessiveInvalidCallMustUseException() * @dataProvider requestProvider * @group integration */ + #[DataProvider('requestProvider')] + #[Group('integration')] public function testAsyncSendRequest($method, $uri, array $headers, $body) { if (null != $body) { @@ -124,14 +128,15 @@ public function testAsyncSendRequest($method, $uri, array $headers, $body) } /** - * @group integration + * @group integration */ + #[Group('integration')] public function testSendAsyncWithInvalidUri() { $request = self::$messageFactory->createRequest( 'GET', $this->getInvalidUri(), - $this->defaultHeaders + self::$defaultHeaders ); $exception = null; @@ -159,6 +164,8 @@ public function testSendAsyncWithInvalidUri() * @dataProvider requestWithOutcomeProvider * @group integration */ + #[Group('integration')] + #[DataProvider('requestWithOutcomeProvider')] public function testSendAsyncRequestWithOutcome($uriAndOutcome, $protocolVersion, array $headers, $body) { if ('1.0' === $protocolVersion) { diff --git a/src/HttpBaseTest.php b/src/HttpBaseTest.php index cbf7a4f..e735126 100644 --- a/src/HttpBaseTest.php +++ b/src/HttpBaseTest.php @@ -10,8 +10,6 @@ abstract class HttpBaseTest extends TestCase { - use PhpUnitBackwardCompatibleTrait; - /** * @var string */ @@ -36,7 +34,7 @@ abstract class HttpBaseTest extends TestCase /** * @var array */ - protected $defaultHeaders = [ + protected static $defaultHeaders = [ 'Connection' => 'close', 'User-Agent' => 'PHP HTTP Adapter', 'Content-Length' => '0', @@ -61,13 +59,13 @@ public static function tearDownAfterClass(): void } } - public function requestProvider(): array + public static function requestProvider(): array { $sets = [ - 'methods' => $this->getMethods(), - 'uris' => [$this->getUri()], - 'headers' => $this->getHeaders(), - 'body' => $this->getBodies(), + 'methods' => self::getMethods(), + 'uris' => [self::getUri()], + 'headers' => self::getHeaders(), + 'body' => self::getBodies(), ]; $cartesianProduct = new CartesianProduct($sets); @@ -84,13 +82,13 @@ public function requestProvider(): array }); } - public function requestWithOutcomeProvider(): array + public static function requestWithOutcomeProvider(): array { $sets = [ - 'urisAndOutcomes' => $this->getUrisAndOutcomes(), - 'protocolVersions' => $this->getProtocolVersions(), - 'headers' => $this->getHeaders(), - 'body' => $this->getBodies(), + 'urisAndOutcomes' => self::getUrisAndOutcomes(), + 'protocolVersions' => self::getProtocolVersions(), + 'headers' => self::getHeaders(), + 'body' => self::getBodies(), ]; $cartesianProduct = new CartesianProduct($sets); @@ -98,7 +96,7 @@ public function requestWithOutcomeProvider(): array return $cartesianProduct->compute(); } - private function getMethods(): array + private static function getMethods(): array { return [ 'GET', @@ -116,7 +114,7 @@ private function getMethods(): array * * @return string|null */ - protected function getUri(array $query = []) + protected static function getUri(array $query = []) { return !empty($query) ? PHPUnitUtility::getUri().'?'.http_build_query($query, '', '&') @@ -134,25 +132,25 @@ protected function getInvalidUri() /** * @return array */ - private function getUrisAndOutcomes() + private static function getUrisAndOutcomes() { return [ [ - $this->getUri(['client_error' => true]), + self::getUri(['client_error' => true]), [ 'statusCode' => 400, 'reasonPhrase' => 'Bad Request', ], ], [ - $this->getUri(['server_error' => true]), + self::getUri(['server_error' => true]), [ 'statusCode' => 500, 'reasonPhrase' => 'Internal Server Error', ], ], [ - $this->getUri(['redirect' => true]), + self::getUri(['redirect' => true]), [ 'statusCode' => 302, 'reasonPhrase' => 'Found', @@ -165,7 +163,7 @@ private function getUrisAndOutcomes() /** * @return array */ - private function getProtocolVersions() + private static function getProtocolVersions() { return ['1.1', '1.0']; } @@ -173,14 +171,14 @@ private function getProtocolVersions() /** * @return string[] */ - private function getHeaders() + private static function getHeaders() { - $headers = $this->defaultHeaders; + $headers = self::$defaultHeaders; $headers['Accept-Charset'] = 'utf-8'; $headers['Accept-Language'] = 'en'; return [ - $this->defaultHeaders, + self::$defaultHeaders, $headers, ]; } @@ -188,18 +186,18 @@ private function getHeaders() /** * @return array */ - private function getBodies() + private static function getBodies() { return [ null, - http_build_query($this->getData(), '', '&'), + http_build_query(self::getData(), '', '&'), ]; } /** * @return array */ - private function getData() + private static function getData() { return ['param1' => 'foo', 'param2' => ['bar', ['baz']]]; } @@ -223,7 +221,7 @@ protected function assertResponse(ResponseInterface $response, array $options = if (null === $options['body']) { $this->assertEmpty($response->getBody()->__toString()); } else { - $this->assertStringContainsString($options['body'], $response->getBody()->__toString()); + self::assertStringContainsString($options['body'], $response->getBody()->__toString()); } } diff --git a/src/HttpClientTest.php b/src/HttpClientTest.php index aaaf7a4..884a319 100644 --- a/src/HttpClientTest.php +++ b/src/HttpClientTest.php @@ -2,6 +2,8 @@ namespace Http\Client\Tests; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use Psr\Http\Client\ClientInterface; use Psr\Http\Client\NetworkExceptionInterface; @@ -37,6 +39,8 @@ abstract protected function createHttpAdapter(): ClientInterface; * @dataProvider requestProvider * @group integration */ + #[Group('integration')] + #[DataProvider('requestProvider')] public function testSendRequest($method, $uri, array $headers, $body) { if (null != $body) { @@ -65,6 +69,8 @@ public function testSendRequest($method, $uri, array $headers, $body) * @dataProvider requestWithOutcomeProvider * @group integration */ + #[Group('integration')] + #[DataProvider('requestWithOutcomeProvider')] public function testSendRequestWithOutcome($uriAndOutcome, $protocolVersion, array $headers, $body) { if ('1.0' === $protocolVersion) { @@ -95,12 +101,13 @@ public function testSendRequestWithOutcome($uriAndOutcome, $protocolVersion, arr /** * @group integration */ + #[Group('integration')] public function testSendWithInvalidUri() { $request = self::$messageFactory->createRequest( 'GET', $this->getInvalidUri(), - $this->defaultHeaders + self::$defaultHeaders ); $this->expectException(NetworkExceptionInterface::class); diff --git a/src/HttpFeatureTest.php b/src/HttpFeatureTest.php index a8faf33..7823ffd 100644 --- a/src/HttpFeatureTest.php +++ b/src/HttpFeatureTest.php @@ -9,8 +9,6 @@ abstract class HttpFeatureTest extends TestCase { - use PhpUnitBackwardCompatibleTrait; - /** * @var MessageFactory */ diff --git a/src/PhpUnitBackwardCompatibleTrait.php b/src/PhpUnitBackwardCompatibleTrait.php index 05f094d..89380a9 100644 --- a/src/PhpUnitBackwardCompatibleTrait.php +++ b/src/PhpUnitBackwardCompatibleTrait.php @@ -4,6 +4,9 @@ use PHPUnit\Framework\TestCase; +/** + * @deprecated this trait was to help using phpunit 7 and 8 which are obsolete. this trait will be removed in the next major version. + */ trait PhpUnitBackwardCompatibleTrait { public static function assertStringContainsString(string $needle, string $haystack, string $message = ''): void