From 513f508687e7b304e736f6b15f1f32ff0b603f3f Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sat, 16 Mar 2024 09:41:16 +0100 Subject: [PATCH] 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', + ], + ]); + } +}