Can't test throwing an exception. Help needed
bu4ak opened this issue · 0 comments
bu4ak commented
PHP version: 8.0.2
Description
After adding 'httplug.factory.mock', the HttpMethodsClient is returned from the container.
Additional context
services.yaml
Http\Client\HttpClient $PDAHttpClient: '@httplug.client.pda'test/httplug.yaml
httplug:
clients:
pda:
factory: 'httplug.factory.mock'
plugins:
- vcr:
mode: replayPDAService.php
...
public function __construct(
HttpClient $PDAHttpClient
) {
$this->httpClient = $PDAHttpClient;
}
...
public function executeRequest(RequestInterface $request): string
{
....
$response = $this->httpClient->sendRequest($request);
...
}ClientTest.php
...
$exception = new NetworkException('Could not resolve host', $this->createMock(Request::class));
$this->getContainer()->get('httplug.client.mock')->addException($exception);
$this->getContainer()->get(PDAService::class)->executeRequest(...);
...Inside the PDAService constructor comes Http\Client\Common\HttpMethodsClient instead of Http\Mock\Client.
And instead of throwing an exception, it tries to find for a vcr fixture.
Other tests that work with vcr are performed correctly.
How can I test a case where an http client should throws a transport error?