第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).