12

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 !

Stephan Vierkant
  • 9,674
  • 8
  • 61
  • 97
Rayhan
  • 135
  • 1
  • 1
  • 7

2 Answers2

27

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>
[...]
vincent PHILIPPE
  • 975
  • 11
  • 26
4

In my case the tests/bootstrap.php file was not in sync with the one of the phpunit-bridge recipe. The recipe was not executed because I updated Symfony 3.4 (without flex) to Symfony 4.4.

After installing the recipe with composer recipes:install symfony/phpunit-bridge --force -v the following files were overridden:

  • .env.test
  • phpunit.xml.dist
  • tests/bootstrap.php

Now the .env.test gets loaded and the KERNEL_CLASS env variable, which is defined there, is respected correctly.

stollr
  • 6,534
  • 4
  • 43
  • 59