-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
The LogicException in WebTestCase.php is not correct. #30420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can you explain how the |
I think the error can also occur when the test client isn't enabled in the framework bundle config. |
Had this issue too, when I ran the command: |
Does someone want to create a PR also including the |
Ok, couldn't reproduce this on a clean install anymore but went back to our original project. Our application runs in a docker container where we have set up environment variables on machine base, and because it is on machine base the Because now our application is running under Do we want to throw another exception that tests should be ran under |
the message should talk about the |
btw, we can even check which message should be used, as we can check whether browser-kit is installed (using |
@SerkanYildiz if I can I would gladly contribute in any way I can! If you'll allow me I'd gladly work ona fix for this and create a merge request. |
Hi @mehlichmeyer, I already created a PR (#30479) to fix this issue. |
… provide clearer exception message (SerkanYildiz) This PR was squashed before being merged into the 3.4 branch (closes #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 | #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
I would like to add a small hint for others who might also come here after getting this error, because it was not clear what the real problem was at the beginning. I get this message after I upgraded my project from Symfony 4.4 to 5.2. In case you use <env name="APP_ENV" value="test"/> Running PHPUnit with tests using SolutionYou have to force <env name="APP_ENV" value="testing" force="true"/> |
If you want a prod env, you need to config/packages/framework.yaml add: when@prod:
framework:
test: true
session:
storage_factory_id: session.storage.factory.mock_file
and into phpunit.xml.dist add APP_ENV = prod: <?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/bin/.phpunit/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="tests/bootstrap.php"
convertDeprecationsToExceptions="false"
>
<php>
<server name="APP_ENV" value="prod" force="true" />
...
</php> |
Symfony version(s) affected: 4.2
Description
In the WebTestCase class there is an error with the LogicException that is being thrown. The message is hardcoded to "You cannot create the client used in functional tests if the BrowserKit component is not available. Try running "composer require symfony/browser-kit".".
This error can however also occur if the browser-kit is installed.
How to reproduce
Go to vendor/symfony/framework-bundle/Test/WebTestCase.php and look at the try catch in the createClient() function.
Possible Solution
Change the message
Additional context
For me this error occured when I didn't have my phpunit configured in phpstorm.
The text was updated successfully, but these errors were encountered: