在windows7 的 xampp下安装phpunit小记,并且解决YII的require<PHPunit/Runner/Version.php> falied to open stream错误
phpunit是xunit系列中的用于php单元测试的软件,支持多种系统。我的php是在windows7下的xampp中,安装phpunit的方法都大同小异,但是要注意的是在安装phpunit之前最好对php进行升级。
具体的安装步骤:
1. 在windows下启动cmd,并进入xampp目录下的php文件夹。
cd E:/xampp/php
2. 升级php
pear upgrade-all
3.更新下载phpunit的通道,输下以下三行命令
pear channel-discover pear.phpunit.de pear channel-discover components.ez.no pear channel-discover pear.symfony-project.com
4.下载并安装phpunit
pear install phpunit/PHPUnit
5. 安装完成后,如果正常的话在php目录下会有phpunit和phpunit.bat文件,如果没有安装成功,检查下pear,php是否更新成功。
6. 另外,安装完之后,检查php\pear\PHPUnit\Extensions 目录下是否有包含Selenium开头的文件以及文件夹,如果不存在,则需要另外安装:
pear install phpunit/PHPUnit_Selenium
否则使用的时候会提示找不到文件:Failed opening required 'PHPUnit/Extensions/SeleniumTestCase.php'
7. 在Yii下使用phpunit时,有下面两点注意事项:
A. 如果phpunit的版本大于3.7,那么则将下面这三行代码注释掉,否则会报require<PHPunit/Runner/Version.php> falied to open stream的错误
require_once('PHPUnit/Runner/Version.php'); require_once('PHPUnit/Util/Filesystem.php'); // workaround for PHPUnit <= 3.6.11 require_once('PHPUnit/Autoload.php');
B. 如果版本小于3.6.1则,注释掉下面代码
if (in_array('phpunit_autoload', spl_autoload_functions())) { // PHPUnit >= 3.7 'phpunit_autoload' was obsoleted spl_autoload_unregister('phpunit_autoload'); Yii::registerAutoloader('phpunit_autoload'); }