Skip to content

Commit 1ddf3af

Browse files
committed
[Test] Throw a better error HttpClient is not installed
1 parent 204c21a commit 1ddf3af

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
4747
use Symfony\Component\DependencyInjection\Reference;
4848
use Symfony\Component\Finder\Finder;
49-
use Symfony\Component\HttpClient\HttpClient;
5049
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
5150
use Symfony\Component\Validator\Validator\ValidatorInterface;
5251
use Symfony\Component\Yaml\Yaml;
@@ -129,11 +128,7 @@ public function load(array $configs, ContainerBuilder $container): void
129128
$container->registerForAutoconfiguration(FilterInterface::class)
130129
->addTag('api_platform.filter');
131130

132-
if ($container->hasParameter('test.client.parameters') && class_exists(AbstractBrowser::class)) {
133-
if (!class_exists(HttpClient::class)) {
134-
throw new RuntimeException('Run "composer require --dev symfony/http-client" to use the test client"');
135-
}
136-
131+
if ($container->hasParameter('test.client.parameters') && class_exists(AbstractBrowser::class) && trait_exists('Symfony\Component\HttpClient\HttpClientTrait')) {
137132
$loader->load('test.xml');
138133
}
139134
}

src/Bridge/Symfony/Bundle/Test/ApiTestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ protected static function createClient(array $kernelOptions = [], array $default
5050
*/
5151
$client = $kernel->getContainer()->get('test.api_platform.client');
5252
} catch (ServiceNotFoundException $e) {
53-
if (class_exists(KernelBrowser::class)) {
53+
if (class_exists(KernelBrowser::class) && trait_exists('Symfony\Component\HttpClient\HttpClientTrait')) {
5454
throw new \LogicException('You cannot create the client used in functional tests if the "framework.test" config is not set to true.');
5555
}
56-
throw new \LogicException('You cannot create the client used in functional tests if the BrowserKit component is not available. Try running "composer require symfony/browser-kit".');
56+
throw new \LogicException('You cannot create the client used in functional tests if the BrowserKit and HttpClient components are not available. Try running "composer require --dev symfony/browser-kit symfony/http-client".');
5757
}
5858

5959
$client->setDefaultOptions($defaultOptions);

0 commit comments

Comments
 (0)