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 相关文章推荐
在Windows下编译适用于PHP 5.2.12及5.2.13的eAccelerator.dll(附下载)
May 04 PHP
Windows7下PHP开发环境安装配置图文方法
May 20 PHP
PHP中判断变量为空的几种方法分享
Aug 26 PHP
完美实现wordpress禁止文章修订和自动保存的方法
Nov 03 PHP
PHP中__FILE__、dirname与basename用法实例分析
Dec 01 PHP
php搜索文件程序分享
Oct 30 PHP
学习php设计模式 php实现模板方法模式
Dec 08 PHP
Thinkphp和onethink实现微信支付插件
Apr 13 PHP
php生成酷炫的四个字符验证码
Apr 22 PHP
php如何执行非缓冲查询API
Jul 22 PHP
Laravel 框架返回状态拦截代码
Oct 18 PHP
php 实现简单的登录功能示例【基于thinkPHP框架】
Dec 02 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
自己做矿石收音机
2021/03/02 无线电
注册页面之前先验证用户名是否存在的php代码
2012/07/14 PHP
PHP中empty和isset对于参数结构的判断及empty()和isset()的区别
2015/11/15 PHP
Yii2使用dropdownlist实现地区三级联动功能的方法
2016/07/18 PHP
[原创]PHP正则匹配中英文、数字及下划线的方法【用户名验证】
2017/08/01 PHP
详解PHP版本兼容之openssl调用参数
2018/07/25 PHP
php求斐波那契数的两种实现方式【递归与递推】
2019/09/09 PHP
javascript 建设银行登陆键盘
2008/06/10 Javascript
使用jQuery将多条数据插入模态框的实现代码
2014/10/08 Javascript
在Node.js应用中读写Redis数据库的简单方法
2015/06/30 Javascript
JS拖动鼠标画出方框实现鼠标选区的方法
2015/08/05 Javascript
jQuery实现对无序列表的排序功能(附demo源码下载)
2016/06/25 Javascript
JS中parseInt()和map()用法分析
2016/12/16 Javascript
详解Vue生命周期的示例
2017/03/10 Javascript
利用JQuery操作iframe父页面、子页面的元素和方法汇总
2017/09/10 jQuery
NodeJS实现自定义流的方法
2018/08/01 NodeJs
原生JS实现$.param() 函数的方法
2018/08/10 Javascript
JS实现查找数组中对象的属性值是否存在示例
2019/05/24 Javascript
js设计模式之单例模式原理与用法详解
2019/08/15 Javascript
微信小程序动态设置图片大小的方法
2019/11/21 Javascript
Javascript执行流程细节原理解析
2020/05/14 Javascript
Django model序列化为json的方法示例
2018/10/16 Python
Python中整数的缓存机制讲解
2019/02/16 Python
Python imutils 填充图片周边为黑色的实现
2020/01/19 Python
django 外键创建注意事项说明
2020/05/20 Python
python基于selenium爬取斗鱼弹幕
2021/02/20 Python
使用HTML5中的contentEditable来将多行文本自动增高
2016/03/01 HTML / CSS
免税水晶:Duty Free Crystal
2019/05/13 全球购物
两年的个人工作自我评价
2014/01/10 职场文书
青年文明号事迹材料
2014/01/18 职场文书
消防先进事迹材料
2014/02/10 职场文书
出国签证在职证明
2014/09/20 职场文书
工作年限证明模板
2015/06/15 职场文书
餐厅服务员管理制度
2015/08/05 职场文书
人生一定要学会的三样东西:放下、忘记、珍惜
2019/08/21 职场文书
MongoDB使用profile分析慢查询的步骤
2021/04/30 MongoDB