Skip to content

Commit 059ba38

Browse files
committed
bug symfony#30479 Check if Client exists when test.client does not exist, to provide clearer exception message (SerkanYildiz)
This PR was squashed before being merged into the 3.4 branch (closes symfony#30479). Discussion ---------- Check if Client exists when test.client does not exist, to provide clearer exception message | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#30420 | License | MIT The `DotEnv` component does not overwrite by using environment variables declared in `.env` files. In the `FrameworkExtension` will be checked if the framework.test config is set to a non-false value, if so it will load the `test.xml` file which contains the definition for the `test.client` service. When running `php bin/phpunit` it will use `phpunit.xml.dist` but because we defined `APP_ENV` in our system it will not load `test.xml` so when creating a client to do functional tests, we'll get an exception which isn't correct: `You cannot create the client used in functional tests if the BrowserKit component is not available. Try running "composer require symfony/browser-kit"` This PR aims to add a clearer exception message which indicates what really should be done to fix the error message. Commits ------- b429950 Check if Client exists when test.client does not exist, to provide clearer exception message
2 parents 860884a + b429950 commit 059ba38

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ protected static function createClient(array $options = [], array $server = [])
3636
try {
3737
$client = $kernel->getContainer()->get('test.client');
3838
} 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".');
39+
if (class_exists(Client::class)) {
40+
throw new \LogicException('You cannot create the client used in functional tests if the "framework.test" config is not set to true.');
41+
}
42+
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"');
4043
}
4144

4245
$client->setServerParameters($server);

0 commit comments

Comments
 (0)