首先,我的开发计算机没有互联网接入,所以我不能从PEAR或Composer安装PHPUnit,然后我只下载。phar存档。
然后我写了一个类与PHPUnit类继承:
require_once './TU/PHPUnit/phpunit.phar';
class A_TEST extends PHPUnit_Framework_TestSuite {
public static function myRunFunction(){}
}
当我调用对象$t = new A_TEST();
时,我得到以下错误:
#!/usr/bin/env php
Notice: Undefined index: argv in phar://C:/Program Files/myPath/TU/PHPUnit/phpunit.phar/phpunit/TextUI/Command.php on line 132
Catchable fatal error: Argument 1 passed to PHPUnit_TextUI_Command::run() must be an array, null given, called in phar://C:/Program Files/myPath/TU/PHPUnit/phpunit.phar/phpunit/TextUI/Command.php on line 132
and defined in phar://C:/Program Files/myPath/TU/PHPUnit/phpunit.phar/phpunit/TextUI/Command.php on line 139
是否有更多的配置做,使其工作?
PHPUnit意味着从命令行运行。
错误信息表明您没有按照设计的方式使用PHPUnit"可执行文件"。(缺少argv
条目,应该从命令行环境向下传递)
要使用默认配置php -f path/to/phpunit.phar path/to/tests
运行测试,应该足够。
配置可以使用命令行选项或配置文件完成。
请注意,phpunit有它自己的命名方案。(测试方法前缀为test
,测试调用后缀为Test
)。
你的例子也不是常用的方式来使用PHPUnit_Framework_TestSuite
。如果你想自己处理的话,你通常会把测试或对测试类的引用作为构造函数参数传递。我建议使用配置文件来创建您的套装,因为它更容易管理xml配置,并且不需要任何额外的代码(可能导致错误,未经测试的代码或至少不必要的样板)
$suite = new PHPUnit_Framework_TestSuite;
$suite->addTest(new MyTest('testEpicStuff'));
或
$suite = new PHPUnit_Framework_TestSuite(
new ReflectionClass('MyTest') // run all tests in the class
);