使用Pear安装PHPUnit

简介: PHPUnit是一个PHP的一个测试框架,在我们做单元测试的时候经常使用它。我们可以通过Pear这个PHP扩展应用库来安装它。当然你也可以不使用这个方法来安装,但是使用Pear的确是很方便,同时也是PHPUnit推荐的方法。 这里我们使用ubuntu作为示例系统,使用apt-get轻松的安装Pear (windows可以使用go-pear.bat脚本) : 1

PHPUnit是一个PHP的一个测试框架,在我们做单元测试的时候经常使用它。我们可以通过Pear这个PHP扩展应用库来安装它。当然你也可以不使用这个方法来安装,但是使用Pear的确是很方便,同时也是PHPUnit推荐的方法。

这里我们使用ubuntu作为示例系统,使用apt-get轻松的安装Pear (windows可以使用go-pear.bat脚本) :

1
sudo apt-get install php-pear

然后我们来添加channel:

1
2
3
4
5
sudo su      #使用su权限,使用完后不要忘记exit。
pear channel-discover pear.phpunit.de
pear channel-discover components.ez.no
pear channel-discover pear.symfony-project.com
exit     #退出su的使用。

然后我们来安装PHPUnit:

1
sudo pear install phpunit /PHPUnit

如果你的pear版本没问题,你应该已经安装了PHPUnit,你会看到install ok之类的字样,类似于:

1
2
3
4
5
install ok: channel: //pear .phpunit.de /DbUnit-1 .0.3
install ok: channel: //pear .phpunit.de /File_Iterator-1 .2.6
install ok: channel: //pear .phpunit.de /PHPUnit_MockObject-1 .0.9
install ok: channel: //pear .phpunit.de /PHPUnit_Selenium-1 .0.3
install ok: channel: //pear .phpunit.de /PHP_CodeCoverage-1

但是如果你的Pear版本有问题,你也许会看到下面的提示:

1
2
3
4
5
6
7
8
9
10
11
12
13
Did not download optional dependencies: pear /XML_RPC2 , use --alldeps to download automatically
phpunit /PHPUnit requires PEAR Installer (version >= 1.9.3), installed version is 1.9.1
phpunit /PHPUnit can optionally use package "pear/XML_RPC2"
phpunit /PHPUnit can optionally use PHP extension "dbus"
phpunit /DbUnit requires PEAR Installer (version >= 1.9.2), installed version is 1.9.1
phpunit /File_Iterator requires PEAR Installer (version >= 1.9.2), installed version is 1.9.1
phpunit /PHP_CodeCoverage requires PEAR Installer (version >= 1.9.2), installed version is 1.9.1
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.2), installed version is 1.9.1
phpunit /PHPUnit_Selenium requires PEAR Installer (version >= 1.9.2), installed version is 1.9.1
No valid packages found
install failed

因为使用了1.9.1版本的pear,但是PHPUnit却要求1.9.2以上。那么我们更新一下pear就可以了:

1
2
sudo pear channel-update pear.php.net
sudo pear upgrade-all

这样我们的Pear就更新到最新了,再次使用

1
sudo pear install phpunit /PHPUnit

来安装PHPUnit,应该就可以看到Install ok了。

当然,有时候敌人还是很顽固的,比如我们遇到这样一个问题:即使我们更换了源,也使用了pear upgrade-all更新了内容,但是在我们继续安装的时候碰到这样一个错误:

1
2
No releases available for package "pear.phpunit.de/PHPUnit"
install failed

这个错误很有可能是本地缓存造成的,下面我们来使用

1
sudo pear clear -cache

这个命令来清除掉缓存, 然后继续使用安装命令pear install phpunit/PHPUnit 来安装,估计就不会有什么大问题了。

注:要注意权限问题。如果您是windows用户,就不用输入sudo了。如果您是debian用户,也不用执行sudo,直接输入su,输入密码,然后往下执行就可以了。 如果您是Ubuntu用户,也可以像上面那样输入sudo su,然后输入密码,这样可以获取管理员权限。

目录
相关文章
|
缓存 网络协议 PHP
PECL 和 PEAR 有什么区别?
PECL 和 PEAR 有什么区别?
|
存储 安全 关系型数据库
如何在Xampp中安装PHP GD(GD Graphics Library)
如何在Xampp中安装PHP GD(GD Graphics Library)
930 0
|
JavaScript PHP
PHP composer的安装和使用
PHP composer的安装和使用
131 0
PHP composer的安装和使用
|
关系型数据库 PHP Perl