symfony / recipes

Symfony Recipes Repository
https://github.com/symfony/recipes/blob/flex/main/RECIPES.md
MIT License
953 stars 472 forks source link

[FrameworkBundle] KernelTestCase does not respect test env #1313

Open IndraGunawan opened 2 months ago

IndraGunawan commented 2 months ago

Symfony version(s) affected

7.0.7

Description

getting the following error while running WebTestCase tests

symfony php bin/phpunit
PHPUnit 9.6.19 by Sebastian Bergmann and contributors.

Testing
E                                                                   1 / 1 (100%)

Time: 00:00.102, Memory: 20.00 MB

There was 1 error:

1) App\Tests\WebTest::testSomething
LogicException: You cannot create the client used in functional tests if the "framework.test" config is not set to true.

/tmp/test/vendor/symfony/framework-bundle/Test/WebTestCase.php:50
/tmp/test/tests/WebTest.php:11
/tmp/test/vendor/phpunit/phpunit/phpunit:107

How to reproduce

symfony new --webapp test
cd test
symfony console make:test WebTestCase WebTest
symfony php bin/phpunit

Possible Solution

modify phpunit.xml.dist file

<php>
   ...
-    <server name="APP_ENV" value="test" force="true" />
+    <env name="APP_ENV" value="test" force="true" />
+    <env name="KERNEL_CLASS" value="App\Kernel" />
   ...
</php>

Additional Context

No response