我刚刚开始在一些现有代码上试用 phpunit。我们使用的命名约定是 MyClass 类应该在 MyClass.class.php 中。 PHPUnit 似乎要求该文件应称为 MyClass.php。
有什么办法解决这个问题吗?
我在尝试生成骨架测试类时注意到它:
phpunit --skeleton-test MyClass.class
PHPUnit 3.3.4 by Sebastian Bergmann.
Could not find class "MyClass.class" in "/home/jd/skeleton/classes/MyClass.class.php".
Fatal error: Call to a member function getOutClassName() on a non-object in /usr/share/php/PHPUnit/TextUI/Command.php on line 470
最佳答案
这不是要求,只是假设。您可以编写自己的测试用例。
Skeleton 只是制作了一个“最简单的方法”模型,为所有类虚拟函数制作虚拟函数。
此外,
phpunit --skeleton-test MyClass MyClass.class.php
可能会做你想做的事。
Usage: phpunit [switches] UnitTest [UnitTest.php]
phpunit [switches] <directory>
--skeleton-class Generate Unit class for UnitTest in UnitTest.php.
--skeleton-test Generate UnitTest class for Unit in Unit.php.
所以根据这个推理,如果你不告诉它类在哪个文件中,它会尝试猜测,如果你告诉它类在哪个文件中,它不会猜测。
关于PHPUnit 文件命名约定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/289729/