improve error message when using test client without the BrowserKit component
This commit is contained in:
parent
f82beb51de
commit
7961a29a57
@ -18,6 +18,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
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;
|
||||
@ -223,6 +224,10 @@ class FrameworkExtension extends Extension
|
||||
$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'])) {
|
||||
|
@ -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.
|
||||
@ -32,7 +33,12 @@ abstract class WebTestCase extends KernelTestCase
|
||||
{
|
||||
$kernel = static::bootKernel($options);
|
||||
|
||||
$client = $kernel->getContainer()->get('test.client');
|
||||
try {
|
||||
$client = $kernel->getContainer()->get('test.client');
|
||||
} catch (ServiceNotFoundException $e) {
|
||||
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".');
|
||||
}
|
||||
|
||||
$client->setServerParameters($server);
|
||||
|
||||
return $client;
|
||||
|
Reference in New Issue
Block a user