yii运行phpunit时报错

问题

在Yii中执行测试用例时报错,内容如下:

PHP Warning:  require_once(PHPUnit/Runner/Version.php): 
failed to open stream: 
No such file or directory in /home/work/software/yii/framework/test/CTestCase.php on line 11

Warning: require_once(PHPUnit/Runner/Version.php): 
failed to open stream: 
No such file or directory in /home/work/software/yii/framework/test/CTestCase.php on line 11
PHP Fatal error:  
require_once(): Failed opening required 'PHPUnit/Runner/Version.php' (include_path='...') in /home/work/software/yii/framework/test/CTestCase.php on line 11

Fatal error: require_once(): 
Failed opening required 'PHPUnit/Runner/Version.php' (include_path='...') in /home/work/software/yii/framework/test/CTestCase.php on line 11

原因

使用的phpunit版本为5.7,使用该版本时,不再需要显示包含PHPUnit/Runner/Version.php等头文件了。

而我当前使用的Yii版本为1.1.15,在yii/framework/test/CTestCase.php中可以看到以下内容:

require_once('PHPUnit/Runner/Version.php');
require_once('PHPUnit/Util/Filesystem.php'); // workaround for PHPUnit <= 3.6.11

spl_autoload_unregister(array('YiiBase','autoload'));
require_once('PHPUnit/Autoload.php');

可以看到,它显示包含了phpunit中的PHPUnit/Runner/Version.php, PHPUnit/Util/Filesystem.php, PHPUnit/Autoload.php的文件,将其注释掉即可。

// require_once('PHPUnit/Runner/Version.php');
// require_once('PHPUnit/Util/Filesystem.php'); // workaround for PHPUnit <= 3.6.11

spl_autoload_unregister(array('YiiBase','autoload'));
// require_once('PHPUnit/Autoload.php');

你可能感兴趣的:(yii,phpunit,php)