Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup branch alias and explicitly require legacy message-factory #16

Merged
merged 5 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down
14 changes: 10 additions & 4 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
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:
name: PHPStan
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: PHPStan
uses: docker://oskarstark/phpstan-ga
Expand All @@ -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:
Expand All @@ -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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/.php_cs.cache
/.php-cs-fixer.cache
/composer.lock
/phpunit.xml
/vendor/
Expand Down
8 changes: 2 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -36,11 +37,6 @@
"Http\\Adapter\\Guzzle7\\Tests\\": "tests/"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
}
},
"scripts": {
"test": "@php vendor/bin/phpunit"
}
Expand Down
5 changes: 5 additions & 0 deletions psalm.baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@
<code>$exception-&gt;getResponse()</code>
</PossiblyNullArgument>
</file>
<file src="src/Client.php">
<PossiblyUnusedMethod occurrences="1">
<code>createWithConfig</code>
</PossiblyUnusedMethod>
</file>
</files>
6 changes: 0 additions & 6 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 5 additions & 14 deletions src/Promise.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}

Expand All @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions tests/CurlHttpAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
*/
class CurlHttpAdapterTest extends HttpAdapterTest
{
/**
* {@inheritdoc}
*/
protected function createHandler()
{
return new CurlHandler();
Expand Down
3 changes: 0 additions & 3 deletions tests/CurlHttpAsyncAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
*/
class CurlHttpAsyncAdapterTest extends HttpAsyncAdapterTest
{
/**
* {@inheritdoc}
*/
protected function createHandler()
{
return new CurlHandler();
Expand Down
3 changes: 0 additions & 3 deletions tests/DefaultHttpAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
*/
class DefaultHttpAdapterTest extends HttpClientTest
{
/**
* {@inheritdoc}
*/
protected function createHttpAdapter(): ClientInterface
{
return new Client();
Expand Down
24 changes: 24 additions & 0 deletions tests/DefaultHttpAdapterWithConfigTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

use Http\Adapter\Guzzle7\Client;
use Http\Client\Tests\HttpClientTest;
use Psr\Http\Client\ClientInterface;

/**
* @author David Buchmann <mail@davidbu.ch>
*/
class DefaultHttpAdapterWithConfigTest extends HttpClientTest
{
protected function createHttpAdapter(): ClientInterface
{
$this->defaultHeaders['X-Test'] = 'configuration-value';

return Client::createWithConfig([
'headers' => [
'X-Test' => 'configuration-value',
],
]);
}
}
3 changes: 0 additions & 3 deletions tests/HttpAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
*/
abstract class HttpAdapterTest extends HttpClientTest
{
/**
* {@inheritdoc}
*/
protected function createHttpAdapter(): ClientInterface
{
return new Client(new GuzzleClient(['handler' => $this->createHandler()]));
Expand Down
3 changes: 0 additions & 3 deletions tests/HttpAsyncAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
*/
abstract class HttpAsyncAdapterTest extends HttpAsyncClientTest
{
/**
* {@inheritdoc}
*/
protected function createHttpAsyncClient(): HttpAsyncClient
{
return new Client(new GuzzleClient(['handler' => $this->createHandler()]));
Expand Down
3 changes: 0 additions & 3 deletions tests/MultiCurlHttpAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
*/
class MultiCurlHttpAdapterTest extends HttpAdapterTest
{
/**
* {@inheritdoc}
*/
protected function createHandler()
{
return new CurlMultiHandler();
Expand Down
3 changes: 0 additions & 3 deletions tests/MultiCurlHttpAsyncAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
*/
class MultiCurlHttpAsyncAdapterTest extends HttpAsyncAdapterTest
{
/**
* {@inheritdoc}
*/
protected function createHandler()
{
return new CurlMultiHandler();
Expand Down
3 changes: 0 additions & 3 deletions tests/StreamHttpAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
*/
class StreamHttpAdapterTest extends HttpAdapterTest
{
/**
* {@inheritdoc}
*/
protected function createHandler()
{
return new StreamHandler();
Expand Down
3 changes: 0 additions & 3 deletions tests/StreamHttpAsyncAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
*/
class StreamHttpAsyncAdapterTest extends HttpAsyncAdapterTest
{
/**
* {@inheritdoc}
*/
protected function createHandler()
{
return new StreamHandler();
Expand Down