PHPUnit PHP测试框架安装方法


Posted in PHP onMarch 23, 2011

单元测试是几个现代敏捷开发方法的基础,使得PHPUnit成为许多大型PHP项目的关键工具。这个工具也可以被Xdebug扩展用来生成代码覆盖率报告 ,并且可以与phing集成来自动测试,最后它还可以和Selenium整合来完成大型的自动化集成测试。

Windows平台LAMP环境XAMPP 1.7.3下如何安装PHPUnit呢?

首先,以管理员身份运行cmd,使用pear添加phpunit频道:

D:\xampp\php>pear channel-discover pear.phpunit.de
Channel "pear.phpunit.de" is already initialized

频道添加好,尝试安装PHPUnit:

D:\xampp\php>pear install phpunit/PHPUnit
Unknown remote channel: pear.symfony-project.com
Unknown remote channel: pear.symfony-project.com
Unknown remote channel: components.ez.no
Unknown remote channel: components.ez.no
phpunit/PHPUnit requires PEAR Installer (version >= 1.9.1), installed version is 1.9.0
phpunit/PHPUnit requires package "channel://pear.symfony-project.com/YAML" (version >= 1.0.2)
phpunit/PHPUnit can optionally use PHP extension "dbus"
phpunit/DbUnit requires PEAR Installer (version >= 1.9.1), installed version is1.9.0
phpunit/DbUnit requires package "channel://pear.symfony-project.com/YAML" (version >= 1.0.2)
phpunit/File_Iterator requires PEAR Installer (version >= 1.9.1), installed version is 1.9.0
phpunit/PHP_CodeCoverage requires PEAR Installer (version >= 1.9.1), installed version is 1.9.0
phpunit/PHP_CodeCoverage requires package "channel://components.ez.no/ConsoleTools" (version >= 1.6)
phpunit/PHP_CodeCoverage requires package "phpunit/File_Iterator" (version >= 1.2.2)
phpunit/PHP_CodeCoverage can optionally use PHP extension "xdebug" (version >= 2.0.5)
phpunit/PHPUnit_MockObject requires PEAR Installer (version >= 1.9.1), installed version is 1.9.0
phpunit/PHPUnit_Selenium requires PEAR Installer (version >= 1.9.1), installed version is 1.9.0
phpunit/PHP_TokenStream requires PEAR Installer (version >= 1.9.1), installed version is 1.9.0
phpunit/PHP_TokenStream requires package "channel://components.ez.no/ConsoleTools" (version >= 1.6)
No valid packages found
install failed

从提示看出,需要安装PEAR 1.9.1,而当前PEAR是1.9.0,那就要先升级PEAR版本。

pear list-upgrades可以列出当前可用的更新,
D:\xampp\php>pear.bat list-upgrades
WARNING: channel "pear.php.net" has updated its protocols, use "pear channel-update pear.php.net" to
update

D:\xampp\php>pear channel-update pear.php.net
Updating channel "pear.php.net"
Update of Channel "pear.php.net" succeeded

D:\xampp\php>pear.bat list-upgrades
PEAR.PHP.NET AVAILABLE UPGRADES (STABLE):
=========================================
CHANNEL PACKAGE LOCAL REMOTE SIZE
pear.php.net Archive_Tar 1.3.3 (stable) 1.3.7 (stable) 17.2kB
pear.php.net Console_Getargs 1.3.4 (stable) 1.3.5 (stable) 17.8kB
pear.php.net Mail 1.1.14 (stable) 1.2.0 (stable) 23kB
pear.php.net Mail_Mime 1.5.2 (stable) 1.8.1 (stable) 31kB
pear.php.net Mail_mimeDecode 1.5.1 (stable) 1.5.5 (stable) 11.4kB
pear.php.net Net_SMTP 1.3.4 (stable) 1.4.4 (stable) 12.1kB
pear.php.net Net_Socket 1.0.9 (stable) 1.0.10 (stable) 5.3kB
pear.php.net PEAR 1.9.0 (stable) 1.9.1 (stable) 287kB
pear.php.net Structures_Graph 1.0.3 (stable) 1.0.4 (stable) 30kB
Channel pear.phpunit.de: No upgrades available
ZEND.GOOGLECODE.COM/SVN AVAILABLE UPGRADES (STABLE):
====================================================
CHANNEL PACKAGE LOCAL REMOTE SIZE
zend.googlecode.com/svn zend 1.9.6 (stable) 1.11.1 (stable) -

更新所有可用更新:
D:\xampp\php>pear upgrade-all
Will upgrade channel://pear.php.net/archive_tar
Will upgrade channel://pear.php.net/console_getargs
Will upgrade channel://pear.php.net/mail
Will upgrade channel://pear.php.net/mail_mime
Will upgrade channel://pear.php.net/mail_mimedecode
Will upgrade channel://pear.php.net/net_smtp
Will upgrade channel://pear.php.net/net_socket
Will upgrade channel://pear.php.net/pear
Will upgrade channel://pear.php.net/structures_graph
Will upgrade channel://zend.googlecode.com/svn/zend
Did not download optional dependencies: pear/Auth_SASL, use --alldeps to download automatically
pear/Net_SMTP can optionally use package "pear/Auth_SASL"
downloading Archive_Tar-1.3.7.tgz ...
Starting to download Archive_Tar-1.3.7.tgz (17,610 bytes)
......done: 17,610 bytes
downloading Console_Getargs-1.3.5.tgz ...
Starting to download Console_Getargs-1.3.5.tgz (18,207 bytes)
...done: 18,207 bytes
downloading Mail-1.2.0.tgz ...
Starting to download Mail-1.2.0.tgz (23,214 bytes)
...done: 23,214 bytes
downloading Mail_Mime-1.8.1.tgz ...
Starting to download Mail_Mime-1.8.1.tgz (31,530 bytes)
...done: 31,530 bytes
downloading Mail_mimeDecode-1.5.5.tgz ...
Starting to download Mail_mimeDecode-1.5.5.tgz (11,554 bytes)
...done: 11,554 bytes
downloading Net_SMTP-1.4.4.tgz ...
Starting to download Net_SMTP-1.4.4.tgz (12,264 bytes)
...done: 12,264 bytes
downloading Net_Socket-1.0.10.tgz ...
Starting to download Net_Socket-1.0.10.tgz (5,429 bytes)
...done: 5,429 bytes
downloading PEAR-1.9.1.tgz ...
Starting to download PEAR-1.9.1.tgz (293,587 bytes)
...done: 293,587 bytes
downloading Structures_Graph-1.0.4.tgz ...
Starting to download Structures_Graph-1.0.4.tgz (30,318 bytes)
...done: 30,318 bytes
downloading Zend-1.11.1.tgz ...
Starting to download Zend-1.11.1.tgz (3,638,888 bytes)
...done: 3,638,888 bytes
upgrade-all ok: channel://pear.php.net/Archive_Tar-1.3.7
upgrade-all ok: channel://pear.php.net/Console_Getargs-1.3.5
upgrade-all ok: channel://pear.php.net/Mail-1.2.0
upgrade-all ok: channel://pear.php.net/Mail_Mime-1.8.1
upgrade-all ok: channel://pear.php.net/Net_Socket-1.0.10
upgrade-all ok: channel://pear.php.net/Structures_Graph-1.0.4
upgrade-all ok: channel://zend.googlecode.com/svn/Zend-1.11.1
upgrade-all ok: channel://pear.php.net/Mail_mimeDecode-1.5.5
upgrade-all ok: channel://pear.php.net/Net_SMTP-1.4.4
upgrade-all ok: channel://pear.php.net/PEAR-1.9.1
PEAR: Optional feature webinstaller available (PEAR's web-based installer)
PEAR: Optional feature gtkinstaller available (PEAR's PHP-GTK-based installer)
PEAR: Optional feature gtk2installer available (PEAR's PHP-GTK2-based installer)
PEAR: To install optional features use "pear install pear/PEAR#featurename"

更新成功后,PEAR已经是1.9.1版了,现在可以放心地安装PHPUnit了:

D:\xampp\php>pear install phpunit/PHPUnit
Unknown remote channel: pear.symfony-project.com
Unknown remote channel: pear.symfony-project.com
Unknown remote channel: components.ez.no
Unknown remote channel: components.ez.no
phpunit/PHPUnit requires package "channel://pear.symfony-project.com/YAML" (version >= 1.0.2)
phpunit/PHPUnit can optionally use PHP extension "dbus"
phpunit/DbUnit requires package "channel://pear.symfony-project.com/YAML" (version >= 1.0.2)
phpunit/PHP_CodeCoverage requires package "channel://components.ez.no/ConsoleTools" (version >= 1.6)
phpunit/PHP_CodeCoverage can optionally use PHP extension "xdebug" (version >= 2.0.5)
phpunit/PHP_TokenStream requires package "channel://components.ez.no/ConsoleTools" (version >= 1.6)
downloading File_Iterator-1.2.3.tgz ...
Starting to download File_Iterator-1.2.3.tgz (3,406 bytes)
....done: 3,406 bytes
downloading PHPUnit_MockObject-1.0.3.tgz ...
Starting to download PHPUnit_MockObject-1.0.3.tgz (17,333 bytes)
...done: 17,333 bytes
downloading PHPUnit_Selenium-1.0.1.tgz ...
Starting to download PHPUnit_Selenium-1.0.1.tgz (15,285 bytes)
...done: 15,285 bytes
install ok: channel://pear.phpunit.de/File_Iterator-1.2.3
install ok: channel://pear.phpunit.de/PHPUnit_MockObject-1.0.3
install ok: channel://pear.phpunit.de/PHPUnit_Selenium-1.0.1

上面信息来看,还是没有安装成功,pear.symfony-project.com和components.ez.no两个频道也要添加一下:

D:\xampp\php>pear channel-discover pear.symfony-project.com
Adding Channel "pear.symfony-project.com" succeeded
Discovery of channel "pear.symfony-project.com" succeeded

D:\xampp\php>pear channel-discover components.ez.no
Adding Channel "components.ez.no" succeeded
Discovery of channel "components.ez.no" succeeded

再次尝试安装PHPUnit:

D:\xampp\php>pear install phpunit/PHPUnit
phpunit/PHPUnit can optionally use PHP extension "dbus"
phpunit/PHP_CodeCoverage can optionally use PHP extension "xdebug" (version >= 2.0.5)
downloading PHPUnit-3.5.5.tgz ...
Starting to download PHPUnit-3.5.5.tgz (116,148 bytes)
....................done: 116,148 bytes
downloading DbUnit-1.0.0.tgz ...
Starting to download DbUnit-1.0.0.tgz (38,183 bytes)
...done: 38,183 bytes
downloading PHP_CodeCoverage-1.0.2.tgz ...
Starting to download PHP_CodeCoverage-1.0.2.tgz (109,280 bytes)
...done: 109,280 bytes
downloading YAML-1.0.4.tgz ...
Starting to download YAML-1.0.4.tgz (9,919 bytes)
...done: 9,919 bytes
downloading ConsoleTools-1.6.1.tgz ...
Starting to download ConsoleTools-1.6.1.tgz (869,994 bytes)
...done: 869,994 bytes
downloading PHP_TokenStream-1.0.1.tgz ...
Starting to download PHP_TokenStream-1.0.1.tgz (7,250 bytes)
...done: 7,250 bytes
downloading Base-1.8.tgz ...
Starting to download Base-1.8.tgz (236,357 bytes)
...done: 236,357 bytes
install ok: channel://pear.symfony-project.com/YAML-1.0.4
install ok: channel://components.ez.no/Base-1.8
install ok: channel://pear.phpunit.de/DbUnit-1.0.0
install ok: channel://components.ez.no/ConsoleTools-1.6.1
install ok: channel://pear.phpunit.de/PHP_TokenStream-1.0.1
install ok: channel://pear.phpunit.de/PHP_CodeCoverage-1.0.2
install ok: channel://pear.phpunit.de/PHPUnit-3.5.5

PHPUnit安装成功!!!

PHP 相关文章推荐
使用PHP维护文件系统
Oct 09 PHP
php mssql 时间格式问题
Jan 13 PHP
网站用php实现paypal整合方法
Nov 28 PHP
PHP mb_convert_encoding文字编码的转换函数介绍
Nov 10 PHP
php类常量的使用详解
Jun 08 PHP
PHP 面向对象程序设计(oop)学习笔记 (四) - 异常处理类Exception
Jun 12 PHP
实现PHP框架系列文章(6)mysql数据库方法
Mar 04 PHP
jQuery+php简单实现全选删除的方法
Nov 28 PHP
php删除数组指定元素实现代码
May 03 PHP
php中关于换行的实例写法
Sep 26 PHP
thinkphp5.1框架实现格式化mysql时间戳为日期的方式小结
Oct 10 PHP
PHP预定义接口――Iterator用法示例
Jun 05 PHP
开启CURL扩展,让服务器支持PHP curl函数(远程采集)
Mar 19 #PHP
windows下开发并编译PHP扩展的方法
Mar 18 #PHP
WordPress判断用户是否登录的代码
Mar 17 #PHP
用php的ob_start来生成静态页面的方法分析
Mar 09 #PHP
PHP用GD库生成高质量的缩略图片
Mar 09 #PHP
php GeoIP的使用教程
Mar 09 #PHP
让PHP COOKIE立即生效,不用刷新就可以使用
Mar 09 #PHP
You might like
用PHP生成自己的LOG文件
2006/10/09 PHP
浅析is_writable的php实现
2013/06/18 PHP
php实现图形显示Ip地址的代码及注释
2014/01/20 PHP
Zend Framework分发器用法示例
2016/12/11 PHP
PHP格式化显示时间date()函数代码
2018/10/03 PHP
thinkPHP框架实现的简单计算器示例
2018/12/07 PHP
自己整理的一个javascript日期处理函数
2010/10/16 Javascript
javascript学习笔记(八)正则表达式
2014/10/08 Javascript
JS实现文字掉落效果的方法
2015/05/06 Javascript
无需 Flash 使用 jQuery 复制文字到剪贴板
2016/04/26 Javascript
javascript实现简单的ajax封装示例
2016/12/28 Javascript
vue计算属性和监听器实例解析
2018/05/10 Javascript
浅谈JavaScript 代码整洁之道
2018/10/23 Javascript
解决Vue在封装了Axios后手动刷新页面拦截器无效的问题
2018/11/08 Javascript
angular4+百分比进度显示插件用法示例
2019/05/05 Javascript
JavaScript制作3D旋转相册
2020/08/02 Javascript
js实现时间日期校验
2020/05/26 Javascript
仅用50行代码实现一个Python编写的计算器的教程
2015/04/17 Python
在Python中操作列表之List.pop()方法的使用
2015/05/21 Python
Java Web开发过程中登陆模块的验证码的实现方式总结
2016/05/25 Python
Python内置函数OCT详解
2016/11/09 Python
理论讲解python多进程并发编程
2018/02/09 Python
Python wxpython模块响应鼠标拖动事件操作示例
2018/08/23 Python
Python numpy.zero() 初始化矩阵实例
2019/11/27 Python
迪拜领先运动补剂零售品牌中文站:Sporter商城
2019/08/20 全球购物
DOM和JQuery对象有什么区别
2016/11/11 面试题
优秀实习自我鉴定
2013/12/04 职场文书
工商治理实习生的自我评价
2014/01/15 职场文书
仓库文员岗位职责
2014/04/06 职场文书
外贸业务员求职信
2014/06/16 职场文书
卖车协议书范例
2014/09/16 职场文书
军训阅兵新闻稿
2015/07/17 职场文书
学习经验交流会总结
2015/11/02 职场文书
银行工作心得体会范文
2016/01/23 职场文书
2019通用版新员工入职培训方案!
2019/07/11 职场文书
快消品行业营销模式与盈利模式分享
2019/09/27 职场文书