创建单元测试用例时 PHPUnit 错误

发布于 2024-10-06 07:49:57 字数 293 浏览 0 评论 0原文

我有控制器类“UserController”(在控制器文件夹中),它扩展了BaseController(存在于应用程序文件夹中),

当我右键单击并选择选项“创建PHPUnitTests”时 它给了我以下错误:

phpunit Fatal error: Class 'Base Controller' not found 

谁能告诉我为什么会收到此错误以及我必须为此配置什么。
我使用自定义 php 框架

i have controller class "UserController"(in controller folder) which extends BaseController (present in app folder),

when i right click and select option "Create PHPUnitTests" it gives me following error:

phpunit Fatal error: Class 'Base Controller' not found 

can ayone tell me why i get this error and what i have to configure for the same.
I using custom php framework

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半岛未凉 2024-10-13 07:49:57

您的包含路径可能没有为您的 IDE 正确配置。对于 Netbeans,请按照 Netbeans 用户手册中给出的说明进行操作:

如果您没有使用 include 语句来包含要在 UnitTests 中测试的文件,您还必须引导环境。从 IDE 执行单元测试可能不会运行常规引导文件。考虑将 phpunit.xml 文件添加到您的测试中:

<phpunit backupGlobals="true"
     backupStaticAttributes="false"
     <!--bootstrap="/path/to/bootstrap.php"-->
     colors="false"
     …
<php>
    <includePath>.</includePath>

有关详细信息,请参阅 PHPUnit 手册中的附录:

按照 Netbeans 用户手册中给出的说明进行操作,使 IDE 在运行测试时自动考虑该文件:

Your Include Path is likely not configured correctly for your IDE. For Netbeans, follow the instructions given in the Netbeans User Manual:

If you are not using include statements to include the files to be tested in the UnitTests, you also have to bootstrap the environment. Executing the UnitTests from the IDE will likely not run your regular bootstrap file. Consider adding a phpunit.xml file to your tests:

<phpunit backupGlobals="true"
     backupStaticAttributes="false"
     <!--bootstrap="/path/to/bootstrap.php"-->
     colors="false"
     …
<php>
    <includePath>.</includePath>

See the Appendix in the PHPUnit Manual for more information:

Follow the instructions given in the Netbeans User Manual to make the IDE consider the file automatically when tests are run:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文