網頁

2014年1月14日 星期二

PHPUnit學習筆記-PHPUnit安裝(使用PEAR)

最近比較閒些,想學學PHP及Wordpress的unit test,當然做之前就要先安裝xUnit,在PHP中就是PHPUnit。

安裝方式主要參考How to Install PHPUnit with MAMP on a MacInstalling PEAR and PHPUnit on OS X 10.8 (Mountain Lion)

安裝前,先查看php的資訊
php -v -> PHP 5.4.17 (cli) (built: Aug 25 2013 02:03:38)
which php -> /usr/bin/php

再來安裝PEAR
$sudo cp /private/etc/php.ini.default /private/etc/php.ini
$sudo php /usr/lib/php/install-pear-nozlib.phar 
$sudo pear config-set php_ini /private/etc/php.ini
$sudo pear channel-update pear.php.net
$sudo pecl channel-update pecl.php.net
$sudo pecl config-set php_ini /private/etc/php.ini
$sudo pear upgrade-all
$sudo vim /private/etc/php.ini


找到include_path,將";"拿掉,在雙引號內加入";/usr/lib/php/pear"

在PHPUnit的Readme中有提到
Alternatively, you may use Composer or the PEAR Installer to download and install PHPUnit as well as its dependencies. Please refer to the documentation for details on how to do this.  
可以直接進PEAR Installer查看詳細資料。查看剛安裝好的PEAR。
$ sudo pear -V
PEAR Version: 1.9.4 
PHP Version: 5.4.17 
Zend Engine Version: 2.4.0 
......

再來安裝PHPUnit(此處用PEAR安裝方式,但2014/12/31就停止服務,要改用Composer,方式可看PHPUnit學習筆記-Broken PHP Configuration on Mavericks or later
$sudo pear config-set auto_discover 1
//sudo pear channel-discover
$sudo pear channel-discover pear.phpunit.de
$sudo pear channel-discover components.ez.no
$sudo pear channel-discover pear.symfony-project.com 
$sudo pear channel-discover pear.symfony.com 
$sudo pear install --alldeps phpunit/PHPUnit
$sudo pear install phpunit/DbUnit --alldeps    <-- 可不裝
$sudo pear install phpunit/PHPUnit_Selenium<-- 可不裝


查看PHPUnit
$phpunit --version
PHPUnit 3.7.28 by Sebastian Bergmann.


這樣就表示安裝成功。

沒有留言:

張貼留言