Skip to content

Commit 8c66a52

Browse files
committed
improve error message when using test client without the BrowserKit component
1 parent 9f112b3 commit 8c66a52

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
1919
use Symfony\Bundle\FrameworkBundle\Routing\AnnotatedRouteControllerLoader;
2020
use Symfony\Bundle\FullStack;
21+
use Symfony\Component\BrowserKit\Client;
2122
use Symfony\Component\Cache\Adapter\AbstractAdapter;
2223
use Symfony\Component\Cache\Adapter\AdapterInterface;
2324
use Symfony\Component\Cache\Adapter\ArrayAdapter;
@@ -223,6 +224,10 @@ public function load(array $configs, ContainerBuilder $container)
223224
$container->getDefinition('test.client.history')->setPrivate(true);
224225
$container->getDefinition('test.client.cookiejar')->setPrivate(true);
225226
$container->getDefinition('test.session.listener')->setPrivate(true);
227+
228+
if (!class_exists(Client::class)) {
229+
$container->removeDefinition('test.client');
230+
}
226231
}
227232

228233
if ($this->isConfigEnabled($container, $config['session'])) {

Test/WebTestCase.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Test;
1313

1414
use Symfony\Bundle\FrameworkBundle\Client;
15+
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
1516

1617
/**
1718
* WebTestCase is the base class for functional tests.
@@ -32,7 +33,12 @@ protected static function createClient(array $options = array(), array $server =
3233
{
3334
$kernel = static::bootKernel($options);
3435

35-
$client = $kernel->getContainer()->get('test.client');
36+
try {
37+
$client = $kernel->getContainer()->get('test.client');
38+
} catch (ServiceNotFoundException $e) {
39+
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".');
40+
}
41+
3642
$client->setServerParameters($server);
3743

3844
return $client;

0 commit comments

Comments
 (0)