diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 7367cca..b944d70 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:
@@ -8,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
@@ -35,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 a8dc568..8de2f7d 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:
@@ -7,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
@@ -20,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:
@@ -31,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
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"
}
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
+
+
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..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 {
@@ -70,31 +70,22 @@ 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);
if ($unwrap) {
- if (self::REJECTED == $this->getState()) {
+ if (self::REJECTED === $this->getState()) {
throw $this->exception;
}
@@ -107,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/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/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',
+ ],
+ ]);
+ }
+}
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();