我正在尝试在 Symfony 4 应用程序中使用 WebTestCase 运行基本功能测试。当我运行测试时,我得到以下输出:
1) Tests\Application\EndToEnd\AuthenticationTest::testAuthenticationMethodNotAllowed RuntimeException: Class "App\Kernel" doesn't exist or cannot be autoloaded. Check that the KERNEL_CLASS value in phpunit.xml matches the fully-qualified class name of your Kernel or override the Tests\Application\EndToEnd\AuthenticationTest::createKernel() method.
尝试遵循 this answer 中的建议,我编辑 vendor/phpunit/phpunit/phpunit.xml
并添加此行:
<server name="KERNEL_CLASS" value="AppKernel" />
这就是有趣的地方:我仍然收到关于 App\Kernel
的投诉 - 带有反斜杠 - 不可用。
这告诉我,我可能正在编辑错误的 XML 文件,因为我编辑的值不包含反斜杠。 我应该在哪个 XML 文件中添加我的定义?
最佳答案
我在通过 PHPStorm 运行测试时遇到此错误(它们在手动运行时正在工作)。我必须将“默认配置文件”设置为 /path/to/phpunit.xml
。
- 在“首选项”中,转到“语言和框架”、“PHP”,然后转到“测试框架”
- 确保选择适当的解释器(在我的例子中,它是 Docker 容器的远程解释器)
- 将“默认配置文件”的路径设置为项目本地的
phpunit.xml
或phpunit.xml.dist
关于php - 我是否在正确的位置定义了 KERNEL_CLASS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55164644/