PHPUnit PHP测试框架安装方法

单元测试是几个现代敏捷开发方法的基础,使得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安装成功!!!

时间: 2024-09-21 20:24:16

PHPUnit PHP测试框架安装方法的相关文章

PHPUnit袖珍指南之安装PHPUnit

到此PHPUnit可以通过PHP扩展和程序库(PEAE)获得.PEAR是可重用PHP组件的框架和分发系统.安装PHPUnit可以通过PEAR安装程序命令获得: pear install PHPUnit2 根据PEAR的版本命名标准,适用于PHP5的PHPUnit包称为PHPUnit2.PHPUnit是适用于PHP4的包,这在本书后面关于"在PHP4中使用PHPUnit"一章会提到. 安装只有,能够在本地的PEAR目录中找到PHPUnit的源代码,路径通常是/usr/lib/ php/P

thinkPHP5.0框架安装教程

本文实例讲述了thinkPHP5.0框架安装方法.分享给大家供大家参考,具体如下: ThinkPHP5的环境要求如下: PHP >= 5.4.0 PDO PHP Extension MBstring PHP Extension CURL PHP Extension 严格来说,ThinkPHP无需安装过程,这里所说的安装其实就是把ThinkPHP框架放入WEB运行环境(前提是你的WEB运行环境已经OK),可以通过两种方式获取和安装ThinkPHP. 一.下载ThinkPHP安装 获取ThinkPH

基于JUnit的InstallAnywhere安装程序图形界面自动测试框架

JUnit 简介 JUnit 是一个开源的单元测试框架,用于编写和运行自动测试,由 Erich Gamma 和 Kent Beck 在 1997 年开发完成.它包括以下特性: 提供的 API 可以让你写出测试结果明确的可重用单元测试用例: 提供了三种方式来显示你的测试结果,而且还可以扩展: 提供了单元测试用例成批运行的功能: 超轻量级而且使用简单,没有商业性的欺骗和无用的向导: 整个框架设计良好,易扩展. InstallAnywhere 简介 InstallAnywhere(下文简称 IA)是一

使用Composer安装Yii框架的方法_php实例

本文实例讲述了使用Composer安装Yii框架的方法.分享给大家供大家参考,具体如下: 现在流行使用Composer安装PHP框架,Composer是PHP用来管理依赖关系的工具,Yii,Laravel,七牛等框架或服务都用Composer作为安装的首选工具. 下面以下载安装Yii框架为例学习使用Composer安装PHP框架: 首先去Composer下载安装这个工具. 通过 Composer 安装 Yii 这是安装Yii2.0的首选方法.如果你还没有安装Composer,你可以按照这里的说明

YII框架(1.7&2.0基础版&2.0高级版)应用程序模板安装方法

YII1.7 安装方法:  ① 鼠标右键我的电脑图标-> 选择弹出窗的"属性"选项-->点击"高级"选项卡->在选项卡下面找到"环境变量选项"进入-->在"系统变量(s)"处找到变量名为"Path"双击打开编辑->加入php所在的安装目录即可  ② 打开命令提示符cmd(可以在开始--运行--输入cmd 回车即可) ->进入yii 所在文件下的framework文件夹 如

最受欢迎的5款Node.js端到端测试框架

笔者在本文中会结合自身实践和 GitHub 趋势对比最受欢迎的 Node.js E2E 测试解决方案,期望对大家的技术选型有帮助 测试,尤其是自动化测试在现代 WEB 工程中有着非常重要的角色,与交付过程集成良好的自动化测试流程可以在新版发布时帮你快速回归产品功能,也可以充当产品文档.测试因粒度不同又可以分为单元测试.接口测试.功能测试.在 WEB 领域,功能测试亦称为端到端测试(End to End Test,简称 E2E 测试),笔者在本文中会结合自身实践和 GitHub 趋势对比最受欢迎的

安卓设备安全测试框架DTF

安卓设备测试框架(Android Device Testing Framework ,简称DTF)是一个可以帮助研究人员进行漏洞挖掘的数据收集和分析框架.DTF提供了模块化的方法和内置的API,允许测试人员快速创建脚本来与Android设备进行互动.DTF包含有多个模块,允许测试人员从他们的Android设备获取信息并将这些信息录入数据库,然后开始搜寻漏洞(均无需root权限). 配置要求 要使用DTF,你至少需要如下: JRE 1.7 Python 2.6 or higher A true B

测试框架 Mocha 实例教程

Mocha(发音"摩卡")诞生于2011年,是现在最流行的JavaScript测试框架之一,在浏览器和Node环境都可以使用. 所谓"测试框架",就是运行测试的工具.通过它,可以为JavaScript应用添加测试,从而保证代码的质量. 本文全面介绍如何使用Mocha,让你轻松上手.如果你以前对测试一无所知,本文也可以当作JavaScript单元测试入门.值得说明的是,除了Mocha以外,类似的测试框架还有Jasmine.Karma.Tape等,也很值得学习. 一.安

ios app 自动测试框架

问题描述 ios app 自动测试框架 我现在通过命令行在越狱后的手机上可以安装网上下载的ipa文件 我现在需要模拟运行这些安装好的app,需要 1.启动运行app 2.模拟操作 3.退出应用 我该需要使用什么框架或者工具能够实现啊 我在网上找到的好多都是需要自已的app源码的 没有别的方法了嘛? 求各位大大帮帮忙 解决方案 很高深的样子 mark一下