Skip to content

Commit

Permalink
improve error message when using test client without the BrowserKit c…
Browse files Browse the repository at this point in the history
…omponent
  • Loading branch information
xabbuh committed Dec 27, 2018
1 parent 3be0445 commit 64feb25
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Expand Up @@ -18,6 +18,7 @@
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Routing\AnnotatedRouteControllerLoader;
use Symfony\Bundle\FullStack;
use Symfony\Component\BrowserKit\Client;
use Symfony\Component\Cache\Adapter\AbstractAdapter;
use Symfony\Component\Cache\Adapter\AdapterInterface;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
Expand Down Expand Up @@ -223,6 +224,10 @@ public function load(array $configs, ContainerBuilder $container)
$container->getDefinition('test.client.history')->setPrivate(true);
$container->getDefinition('test.client.cookiejar')->setPrivate(true);
$container->getDefinition('test.session.listener')->setPrivate(true);

if (!class_exists(Client::class)) {
$container->removeDefinition('test.client');
}
}

if ($this->isConfigEnabled($container, $config['session'])) {
Expand Down
8 changes: 7 additions & 1 deletion src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bundle\FrameworkBundle\Test;

use Symfony\Bundle\FrameworkBundle\Client;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;

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

$client = $kernel->getContainer()->get('test.client');
try {
$client = $kernel->getContainer()->get('test.client');
} catch (ServiceNotFoundException $e) {
throw new \LogicException('The BrowserKit component is required to be able to create a client.', $e->getCode(), $e);
}

$client->setServerParameters($server);

return $client;
Expand Down

0 comments on commit 64feb25

Please sign in to comment.