From 427e734c5a2263b909c77c225eb7072e678113c1 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sat, 16 Mar 2024 09:29:13 +0100 Subject: [PATCH 1/5] cleanup branch alias and explicitly require legacy message-factory --- .gitignore | 2 +- composer.json | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 5727179..254ab37 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -/.php_cs.cache +/.php-cs-fixer.cache /composer.lock /phpunit.xml /vendor/ diff --git a/composer.json b/composer.json index e972831..d0a8ace 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,8 @@ "require-dev": { "phpunit/phpunit": "^8.0|^9.3", "php-http/client-integration-tests": "^3.0", - "phpspec/prophecy-phpunit": "^2.0" + "phpspec/prophecy-phpunit": "^2.0", + "php-http/message-factory": "^1.1" }, "provide": { "php-http/client-implementation": "1.0", @@ -36,11 +37,6 @@ "Http\\Adapter\\Guzzle7\\Tests\\": "tests/" } }, - "extra": { - "branch-alias": { - "dev-master": "1.x-dev" - } - }, "scripts": { "test": "@php vendor/bin/phpunit" } From c6975e5dae550cedfb8a5c1b801f3b27aadca2a5 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sat, 16 Mar 2024 09:33:00 +0100 Subject: [PATCH 2/5] latest cs fixes --- .github/workflows/ci.yml | 8 +++++++- src/Client.php | 6 ------ src/Promise.php | 11 +---------- tests/CurlHttpAdapterTest.php | 3 --- tests/CurlHttpAsyncAdapterTest.php | 3 --- tests/DefaultHttpAdapterTest.php | 3 --- tests/HttpAdapterTest.php | 3 --- tests/HttpAsyncAdapterTest.php | 3 --- tests/MultiCurlHttpAdapterTest.php | 3 --- tests/MultiCurlHttpAsyncAdapterTest.php | 3 --- tests/StreamHttpAdapterTest.php | 3 --- tests/StreamHttpAsyncAdapterTest.php | 3 --- 12 files changed, 8 insertions(+), 44 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7367cca..bb5bee6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,11 @@ name: Tests -on: [push, pull_request] +on: + push: + branches: + - '[0-9]+.x' + - '[0-9]+.[0-9]+' + - '[0-9]+.[0-9]+.x' + pull_request: jobs: build: diff --git a/src/Client.php b/src/Client.php index a92ab06..51724a6 100644 --- a/src/Client.php +++ b/src/Client.php @@ -43,17 +43,11 @@ public static function createWithConfig(array $config): Client return new self(self::buildClient($config)); } - /** - * {@inheritdoc} - */ public function sendRequest(RequestInterface $request): ResponseInterface { return $this->sendAsyncRequest($request)->wait(); } - /** - * {@inheritdoc} - */ public function sendAsyncRequest(RequestInterface $request) { $promise = $this->guzzle->sendAsync($request); diff --git a/src/Promise.php b/src/Promise.php index b830216..048b44c 100644 --- a/src/Promise.php +++ b/src/Promise.php @@ -70,25 +70,16 @@ public function __construct(PromiseInterface $promise, RequestInterface $request }); } - /** - * {@inheritdoc} - */ - public function then(callable $onFulfilled = null, callable $onRejected = null) + public function then(?callable $onFulfilled = null, ?callable $onRejected = null) { return new static($this->promise->then($onFulfilled, $onRejected), $this->request); } - /** - * {@inheritdoc} - */ public function getState() { return $this->state; } - /** - * {@inheritdoc} - */ public function wait($unwrap = true) { $this->promise->wait(false); diff --git a/tests/CurlHttpAdapterTest.php b/tests/CurlHttpAdapterTest.php index 730b528..e53912f 100644 --- a/tests/CurlHttpAdapterTest.php +++ b/tests/CurlHttpAdapterTest.php @@ -11,9 +11,6 @@ */ class CurlHttpAdapterTest extends HttpAdapterTest { - /** - * {@inheritdoc} - */ protected function createHandler() { return new CurlHandler(); diff --git a/tests/CurlHttpAsyncAdapterTest.php b/tests/CurlHttpAsyncAdapterTest.php index 86aa4df..f5589f1 100644 --- a/tests/CurlHttpAsyncAdapterTest.php +++ b/tests/CurlHttpAsyncAdapterTest.php @@ -11,9 +11,6 @@ */ class CurlHttpAsyncAdapterTest extends HttpAsyncAdapterTest { - /** - * {@inheritdoc} - */ protected function createHandler() { return new CurlHandler(); diff --git a/tests/DefaultHttpAdapterTest.php b/tests/DefaultHttpAdapterTest.php index 8c32bc0..b4ac79a 100644 --- a/tests/DefaultHttpAdapterTest.php +++ b/tests/DefaultHttpAdapterTest.php @@ -13,9 +13,6 @@ */ class DefaultHttpAdapterTest extends HttpClientTest { - /** - * {@inheritdoc} - */ protected function createHttpAdapter(): ClientInterface { return new Client(); diff --git a/tests/HttpAdapterTest.php b/tests/HttpAdapterTest.php index 867ac6e..cb60c99 100644 --- a/tests/HttpAdapterTest.php +++ b/tests/HttpAdapterTest.php @@ -14,9 +14,6 @@ */ abstract class HttpAdapterTest extends HttpClientTest { - /** - * {@inheritdoc} - */ protected function createHttpAdapter(): ClientInterface { return new Client(new GuzzleClient(['handler' => $this->createHandler()])); diff --git a/tests/HttpAsyncAdapterTest.php b/tests/HttpAsyncAdapterTest.php index a98a3e6..71ec7f4 100644 --- a/tests/HttpAsyncAdapterTest.php +++ b/tests/HttpAsyncAdapterTest.php @@ -14,9 +14,6 @@ */ abstract class HttpAsyncAdapterTest extends HttpAsyncClientTest { - /** - * {@inheritdoc} - */ protected function createHttpAsyncClient(): HttpAsyncClient { return new Client(new GuzzleClient(['handler' => $this->createHandler()])); diff --git a/tests/MultiCurlHttpAdapterTest.php b/tests/MultiCurlHttpAdapterTest.php index 9f6db87..bae535d 100644 --- a/tests/MultiCurlHttpAdapterTest.php +++ b/tests/MultiCurlHttpAdapterTest.php @@ -11,9 +11,6 @@ */ class MultiCurlHttpAdapterTest extends HttpAdapterTest { - /** - * {@inheritdoc} - */ protected function createHandler() { return new CurlMultiHandler(); diff --git a/tests/MultiCurlHttpAsyncAdapterTest.php b/tests/MultiCurlHttpAsyncAdapterTest.php index 9cf4fda..40ac08f 100644 --- a/tests/MultiCurlHttpAsyncAdapterTest.php +++ b/tests/MultiCurlHttpAsyncAdapterTest.php @@ -11,9 +11,6 @@ */ class MultiCurlHttpAsyncAdapterTest extends HttpAsyncAdapterTest { - /** - * {@inheritdoc} - */ protected function createHandler() { return new CurlMultiHandler(); diff --git a/tests/StreamHttpAdapterTest.php b/tests/StreamHttpAdapterTest.php index cf742e4..36f45c8 100644 --- a/tests/StreamHttpAdapterTest.php +++ b/tests/StreamHttpAdapterTest.php @@ -11,9 +11,6 @@ */ class StreamHttpAdapterTest extends HttpAdapterTest { - /** - * {@inheritdoc} - */ protected function createHandler() { return new StreamHandler(); diff --git a/tests/StreamHttpAsyncAdapterTest.php b/tests/StreamHttpAsyncAdapterTest.php index a4f29f8..10564a4 100644 --- a/tests/StreamHttpAsyncAdapterTest.php +++ b/tests/StreamHttpAsyncAdapterTest.php @@ -11,9 +11,6 @@ */ class StreamHttpAsyncAdapterTest extends HttpAsyncAdapterTest { - /** - * {@inheritdoc} - */ protected function createHandler() { return new StreamHandler(); From 513f508687e7b304e736f6b15f1f32ff0b603f3f Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sat, 16 Mar 2024 09:41:16 +0100 Subject: [PATCH 3/5] add test for createWithConfig --- .github/workflows/static.yml | 8 +++++++- src/Promise.php | 8 ++++---- tests/DefaultHttpAdapterWithConfigTest.php | 24 ++++++++++++++++++++++ 3 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 tests/DefaultHttpAdapterWithConfigTest.php diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index a8dc568..5b071ec 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -1,5 +1,11 @@ -on: [push, pull_request] name: Static analysis +on: + push: + branches: + - '[0-9]+.x' + - '[0-9]+.[0-9]+' + - '[0-9]+.[0-9]+.x' + pull_request: jobs: phpstan: diff --git a/src/Promise.php b/src/Promise.php index 048b44c..815329d 100644 --- a/src/Promise.php +++ b/src/Promise.php @@ -53,13 +53,13 @@ public function __construct(PromiseInterface $promise, RequestInterface $request $this->state = self::FULFILLED; return $response; - }, function ($reason) use ($request) { + }, function ($reason) { $this->state = self::REJECTED; if ($reason instanceof HttplugException) { $this->exception = $reason; } elseif ($reason instanceof GuzzleExceptions\GuzzleException) { - $this->exception = $this->handleException($reason, $request); + $this->exception = $this->handleException($reason); } elseif ($reason instanceof \Throwable) { $this->exception = new HttplugException\TransferException('Invalid exception returned from Guzzle7', 0, $reason); } else { @@ -85,7 +85,7 @@ public function wait($unwrap = true) $this->promise->wait(false); if ($unwrap) { - if (self::REJECTED == $this->getState()) { + if (self::REJECTED === $this->getState()) { throw $this->exception; } @@ -98,7 +98,7 @@ public function wait($unwrap = true) * * @return HttplugException */ - private function handleException(GuzzleExceptions\GuzzleException $exception, RequestInterface $request) + private function handleException(GuzzleExceptions\GuzzleException $exception) { if ($exception instanceof GuzzleExceptions\ConnectException) { return new HttplugException\NetworkException($exception->getMessage(), $exception->getRequest(), $exception); diff --git a/tests/DefaultHttpAdapterWithConfigTest.php b/tests/DefaultHttpAdapterWithConfigTest.php new file mode 100644 index 0000000..277f419 --- /dev/null +++ b/tests/DefaultHttpAdapterWithConfigTest.php @@ -0,0 +1,24 @@ + + */ +class DefaultHttpAdapterWithConfigTest extends HttpClientTest +{ + protected function createHttpAdapter(): ClientInterface + { + $this->defaultHeaders['X-Test'] = 'configuration-value'; + + return Client::createWithConfig([ + 'headers' => [ + 'X-Test' => 'configuration-value', + ], + ]); + } +} From dc4da394ec91320228ee562fcac11fdc85fb83ae Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Mon, 4 Mar 2024 20:02:42 +0100 Subject: [PATCH 4/5] chore: feat ci deprecations --- .github/workflows/ci.yml | 10 +++++----- .github/workflows/static.yml | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bb5bee6..b944d70 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,18 +14,18 @@ jobs: strategy: max-parallel: 10 matrix: - php: [ '7.3', '7.4', '8.0', '8.1', '8.2'] + php: [ '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] steps: - name: Set up PHP - uses: shivammathur/setup-php@2.5.0 + uses: shivammathur/setup-php@2.30.0 with: php-version: ${{ matrix.php }} coverage: none tools: flex - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Download dependencies run: composer update --no-interaction --prefer-dist --optimize-autoloader --prefer-stable @@ -41,14 +41,14 @@ jobs: runs-on: ubuntu-latest steps: - name: Set up PHP - uses: shivammathur/setup-php@2.5.0 + uses: shivammathur/setup-php@2.30.0 with: php-version: 7.3 coverage: none tools: flex - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Download dependencies run: composer update --no-interaction --prefer-dist --optimize-autoloader --prefer-stable --prefer-lowest diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 5b071ec..8de2f7d 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: PHPStan uses: docker://oskarstark/phpstan-ga @@ -26,7 +26,7 @@ jobs: name: PHP-CS-Fixer runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: PHP-CS-Fixer uses: docker://oskarstark/php-cs-fixer-ga with: @@ -37,7 +37,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Psalm uses: docker://vimeo/psalm-github-actions From b88310d0b5c41fbe464543c279299fd1f6c70e63 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sat, 16 Mar 2024 10:04:02 +0100 Subject: [PATCH 5/5] psalm stop complaining about unused method --- psalm.baseline.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/psalm.baseline.xml b/psalm.baseline.xml index 96ab42c..d1aea73 100644 --- a/psalm.baseline.xml +++ b/psalm.baseline.xml @@ -5,4 +5,9 @@ $exception->getResponse() + + + createWithConfig + +