欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

PHPUnit PHP测试框架安装方法

程序员文章站 2022-04-09 10:48:23
单元测试是几个现代敏捷开发方法的基础,使得phpunit成为许多大型php项目的关键工具。这个工具也可以被xdebug扩展用来生成代码覆盖率报告 ,并且可以与phing集成...
单元测试是几个现代敏捷开发方法的基础,使得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安装成功!!!