I'm trying to learn how to make phpunit by testing the User class made by "make:user" but i'm facing this problem when extending "KernelTestCase" and run the test :
LogicException: You must set the KERNEL_CLASS environment variable to the fully-qualified class name of your Kernel in phpunit.xml / phpunit.xml.dist or override the "App\tests\Entity
UsersTest::createKernel()" or "App\tests\Entity\UsersTest::getKernelClass()" method.
Here is my test, i'm trying to test an Entity :
I'm trying to fix it since 2 days with my friend Google but I didn't found any solution. Can you help me ? Thank you guys !
I just got the same problem.
The solution is to update your ./phpunit.xml.dist file to set the KERNEL_CLASS environment variable :
[...]
<php>
<ini name="error_reporting" value="-1" />
<server name="APP_ENV" value="test" force="true" />
<server name="SHELL_VERBOSITY" value="-1" />
<server name="SYMFONY_PHPUNIT_REMOVE" value="" />
<server name="SYMFONY_PHPUNIT_VERSION" value="7.5" />
<server name="KERNEL_CLASS" value="App\Kernel" /> <--- SET KERNEL_CLASS AT THIS LINE
</php>
[...]
<php>
<env name="KERNEL_CLASS" value="App\Kernel" />
</php>
In addition to the solution mentioned by other individuals, it is necessary for the file to be considered in order to use the environment variables from the "phpunit.xml.dist" file.
For example, in PhpStorm, we need to target it in Settings -> Test Frameworks and define the path of phpunit.xml.dist in the "Default configuration file".
Now, you need to find out how to link the phpUnit.xml.dist file with your IDE or CLI.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With