From 5b41739ebceeb7636293654d808fb34af0e12525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Gon=C3=A7alves?= Date: Fri, 22 Dec 2023 14:46:17 +0000 Subject: [PATCH] Do not reload HTTP client fixtures on WebTestCase if no HTTP client fixtures are available (#49) * Do not reload HTTP client fixtures on WebTestCase if no HTTP client fixtures are available * Only get HTTP client fixtures from the provided client if symfony/http-client is installed --- src/Test/WebTestCase.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Test/WebTestCase.php b/src/Test/WebTestCase.php index 120cee4..e3688e2 100644 --- a/src/Test/WebTestCase.php +++ b/src/Test/WebTestCase.php @@ -5,23 +5,22 @@ use Kununu\TestingBundle\Test\Options\Options; use Symfony\Component\HttpFoundation\Response; +use Symfony\Contracts\HttpClient\HttpClientInterface; abstract class WebTestCase extends FixturesAwareTestCase { final protected function doRequest(RequestBuilder $builder, string $httpClientName = 'http_client', ?Options $options = null): Response { - $httpClientFixtures = $this->getHttpClientFixtures($httpClientName); - - if (!$options) { - $options = Options::create(); - } + $httpClientFixtures = interface_exists(HttpClientInterface::class) + ? $this->getHttpClientFixtures($httpClientName) + : null; $this->shutdown(); $client = $this->getKernelBrowser(); - foreach ($httpClientFixtures as $fixtureClass => $fixture) { - $this->loadHttpClientFixtures($httpClientName, $options, $fixtureClass); + foreach ($httpClientFixtures ?? [] as $fixtureClass => $fixture) { + $this->loadHttpClientFixtures($httpClientName, $options ?? Options::create(), $fixtureClass); } $client->request(...$builder->build());