Skip to content

test that mock client can discover a message factory #65

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

Merged
merged 3 commits into from
May 21, 2023
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
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Change Log

## 1.5.2 - 2023-05-23
## 1.6.0 - 2023-05-21

### Fixed

- We actually did fallback to the legacy message factory discovery so 1.5.2 is broken.
Changed to use PSR 17 factory discovery.
If you allow the composer plugin of `php-http/discovery`, things will work out of the box.
When disabled and you do not have a PSR-17 factory installed, you will need to explicitly require one, e.g. `nyholm/psr7`.

## 1.5.2 - 2023-05-17

**Broken, use 1.6.0 instead**

### Removed

Expand Down
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
"require": {
"php": "^7.1 || ^8.0",
"php-http/client-common": "^2.0",
"php-http/discovery": "^1.0",
"php-http/discovery": "^1.16",
"php-http/httplug": "^2.0",
"psr/http-client": "^1.0",
"psr/http-factory": "^1.0",
"psr/http-factory-implementation": "^1.0",
"psr/http-message": "^1.0 || ^2.0",
"symfony/polyfill-php80": "^1.17"
},
Expand All @@ -34,7 +34,10 @@
"phpspec/phpspec": "^5.1 || ^6.1 || ^7.3"
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"php-http/discovery": true
}
},
"autoload": {
"psr-4": {
Expand Down
3 changes: 3 additions & 0 deletions spec/ClientSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ function let(ResponseFactoryInterface $responseFactory)
function it_is_initializable()
{
$this->shouldHaveType(Client::class);

// make sure the client is also instantiable without arguments
new Client();
}

function it_is_an_http_client()
Expand Down
18 changes: 17 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
use Http\Client\Exception;
use Http\Client\HttpAsyncClient;
use Http\Client\HttpClient;
use Http\Discovery\Exception\NotFoundException;
use Http\Discovery\MessageFactoryDiscovery;
use Http\Discovery\Psr17FactoryDiscovery;
use Http\Message\RequestMatcher;
use Http\Message\ResponseFactory;
use Psr\Http\Client\ClientExceptionInterface;
Expand Down Expand Up @@ -72,7 +74,21 @@ public function __construct($responseFactory = null)
);
}

$this->responseFactory = $responseFactory ?: MessageFactoryDiscovery::find();
if ($responseFactory) {
$this->responseFactory = $responseFactory;

return;
}
try {
$this->responseFactory = Psr17FactoryDiscovery::findResponseFactory();
} catch (NotFoundException $notFoundException) {
try {
$this->responseFactory = MessageFactoryDiscovery::find();
} catch (NotFoundException $e) {
// throw the psr-17 exception to make people install the new way and not the old
throw $notFoundException;
}
}
}

/**
Expand Down