yii執行phpunit時報錯

田靖榮發表於2019-02-16

問題

在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`);

相關文章