Skip to content

Commit

Permalink
Do not reload HTTP client fixtures on WebTestCase if no HTTP client f…
Browse files Browse the repository at this point in the history
…ixtures 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
  • Loading branch information
hugo-goncalves-kununu authored Dec 22, 2023
1 parent 126dfa4 commit 5b41739
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/Test/WebTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 5b41739

Please sign in to comment.