功能单元测试
我有一个 PHP 文件,其中有一些函数(不包含在类中)。我正在使用 PHPUnit 进行测试。当我尝试以简单的方式从包含函数的文件生成测试文件时,日志显示:
Could not find class...
是否有可能测试不是方法的函数?
I have got a PHP file in which there are some functions (not included in a class). I am using PHPUnit to testing. When I try to generate in a simply way a test file from a file containing functions, the log says:
Could not find class...
Is there any possibility to test functions which are not methods?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,您可以使用以下内容:
includes/functions.phptests
/MyFunctionTest.php
因此,只要您的函数在范围内,您就可以从测试方法中调用它,就像任何其他 PHP 框架或项目中的任何其他 PHP 函数一样。
Yes, you can with something like this:
includes/functions.php
tests/MyFunctionTest.php
So as long as your function is within scope you can call it from your test method just like any other PHP function in any other PHP framework or project.
如果我是对的,那么 PhpUnit 仅适用于类,因此适用于方法。因此只需将它们转换为用于测试目的的方法即可。应该不难。
If I'm right then PhpUnit works only with classes hence methods. So just convert them into the methods for testing purpose. Shouldn't be hard.