第4章 安装PHPUnit
PHPUnit可以通过PHP扩展和程序库(PEAE)获得。PEAR是可重用PHP组件的框架和分发系统。安装PHPUnit可以通过PEAR安装程序命令获得:
pear install PHPUnit2
根据PEAR的版本命名标准,适用于PHP5的PHPUnit包称为PHPUnit2。PHPUnit是适用于PHP4的包,这在本书后面关于“在PHP4中使用PHPUnit”一章会提到。
安装只有,能够在本地的PEAR目录中找到PHPUnit的源代码,路径通常是/usr/lib/ php/PHPUnit2。
尽管使用PEAR安装程序是PHPUnit唯一支持的安装方法,但你还是可以手工安装。要手工安装,参照以下做法:
1. 从http://pear.php.net/package/PHPUnit2/download下载PHPUnit发布包,然后解压缩,确保目录在php.ini定义的include_path中。
2. 准备phpunit脚本
a. 将pear-phpunit脚本改名为phpunit
b. 将脚本中所有的@php_bin@改名为PHP命令行解释器所在的目录(通常为/usr/bin/ php)。
c. 将此脚本拷贝到一个PATH环境变量所包含的目录中,并将文件属性改为可执行(chmod +x phpunit)。
3. 将PHPUnit2/ Runner/Version.php脚本中的所有@package_version@字符串替换为你所安装的PHPUnit版本(如2.3.0)。
--------------------------------------------------------------------------------------------------------------------
原文
Chapter 4. Installing PHPUnit
PHPUnit[1] is available from the PHP Extension and Application Repository (PEAR), [2] which is a framework and distribution system for reusable PHP components. It can be installed using the PEAR Installer:
[1] http://www.phpunit.de/
[2] http://pear.php.net/
$ pear install PHPUnit2
Due to PEAR's version-naming standard, the PHPUnit package for PHP 5 is called PHPUnit2. PHPUnit is the name of the PHPUnit package for PHP 4 that is the topic of "PHPUnit for PHP 4," later in this book.
After the installation, you can find the PHPUnit source files inside your local PEAR directory; the path is usually /usr/lib/ php/PHPUnit2.
Although using the PEAR installer is the only supported way to install PHPUnit, you can install PHPUnit manually. For manual installation, do the following:
Download a release archive from http://pear.php.net/package/PHPUnit2/download and extract it to a directory that is listed in the include_path of your php.ini configuration file.
Prepare the phpunit script:
Rename the pear-phpunit script to phpunit.
Replace the @php_bin@ string in it with the path to your PHP command-line interpreter (usually /usr/bin/ php).
Copy it to a directory that is in your PATH and make it executable (chmod +x phpunit).
Replace the @package_version@ string in the PHPUnit2/ Runner/Version.php script with the version number of the PHPUnit release you are installing (2.3.0, for instance).