WAMP下安装phpunit

来源:互联网 发布:淘宝网客服电话 编辑:程序博客网 时间:2024/05/22 05:43

php版本5.5.3

phpdir表示php的安装目录

一、pear的安装

1、保存下面内容为go-pear.bat文件到phpdir目录下

@ECHO OFF
set PHP_BIN=php.exe
%PHP_BIN% -d phar.require_hash=0 PEAR\go-pear.phar
pause


2、下载go-pear.phar并保存到phpdir/PEAR目录下


3、进入cmd,到phpdir目录下


4、运行命令:go-pear.bat

提示如下:

Are you installing a system-wide PEAR or a local copy?(system|local) [system]


5、确认无误回车继续

提示如下:

 1. Installation base ($prefix)                   : D:\path_to_your_php\php5.x.x2. Temporary directory for processing            : D:\path_to_your_php\php5.x.x\tmp 3. Temporary directory for downloads             : D:\path_to_your_php\php5.x.x\tmp 4. Binaries directory                            : D:\path_to_your_php\php5.x.x5. PHP code directory ($php_dir)                 : D:\path_to_your_php\php5.x.x\pear 6. Documentation directory                       : D:\path_to_your_php\php5.x.x\docs 7. Data directory                                : D:\path_to_your_php\php5.x.x\data 8. User-modifiable configuration files directory : D:\path_to_your_php\php5.x.x\cfg 9. Public Web Files directory                    : D:\path_to_your_php\php5.x.x\www10. Tests directory                               : D:\path_to_your_php\php5.x.x\tests11. Name of configuration file                    : D:\path_to_your_php\php5.x.x\pear.ini12. Path to CLI php.exe                           : D:\path_to_your_php\php5.x.x1-12, ‘all’ or Enter to continue:


6、确认无误回车继续


7、在phpdir目录下生成环境变量PEAR_ENV.reg文件,双击导入注册表


8、输入pear -V 查看版本信息,输入pear list 查看已安装的包


9、如果pear list查看没有 Image_GraphViz 包和 Log 包,则使用 pear install Log 安装Log,使用 pear install Image_GraphViz


10、安装 Image_GraphViz 时,如果提示不能包含Structures/Graph/Node.php,则

  1. 尝试set查看PHP_PEAR_*相关环境变量是否正确
  2. 尝试关闭cmd窗口,再打开,再pear install Image_GraphViz
  3. 尝试pear install Stuctures_Graph,再pear install Image_GraphViz


11、pear upgrade-all 即可升级所有的包。


二、phpunit的安装

1、进入cmd到phpdir目录下


2、运行下面的命令

pear config-set auto_discover 1pear install pear.phpunit.de/PHPUnit


3、phpunit --version查看安装的版本信息


三、测试

1、在phpdir目录下加入两个文件

calculator.php功能类

class calculator{       function add($p1,$p2)       {           return $p1+$p2;       }   } 

calculatorTest.php测试类,对calculator.php的功能进行测试

require_once("calculator.php");   require_once("PEAR/PHPUnit/Framework/TestCase.php");         class calculatorTest extends PHPUnit_Framework_TestCase       {           public $o;           //开始的时候初始化一个待测试类           function setUp()           {               $this->o = new calculator();           }           //最后消亡的时候清除掉这个类           function tearDown() {                   unset($this->o);           }           function testadd()           {               $r = $this->o->add(1,2);               $e = 5;               //assertEquals和assertTrue基本一样,不过这个返回的参数更加详细               //这里的1+2肯定等于3,我们故意写错看下他的反应。注意这里是故意写错,实际测试时,这些结果必须是完全正确的,因为它的功能就是检测类方法是否正确。               $this->assertEquals($r,$e);           }           function testadd2()           {               $r = $this->o->add(102,106);               $e = 208;               $this->assertTrue($r == $e);           }                  } 

2、进入cmd到phpdir目录下,运行phpunit calculatorTest查看测试结果