什麼是PHPUnit?
PHPUnit是一個輕量級的PHP測試架構。它是在PHP5下面對JUnit3系列版本的完整移植,是xUnit測試架構家族的一員(它們都基于模式先鋒Kent Beck的設計)
Ubuntu上安裝
sudo apt-get install phpunit
驗證PHPUnit安裝成功,指令行輸入phpunit
$ phpunit
安裝成功列印:
PHPUnit 3.6.11 by Sebastian Bergmann.
Usage: phpunit [switches] UnitTest [UnitTest.php]
phpunit [switches] <directory>
如果出現如下的錯誤。
PHP Warning: require_once(PHP/CodeCoverage/Filter.php): failed to open stream: No such file or directory in /usr/bin/phpunit on line 39
PHP Fatal error: require_once(): Failed opening required 'PHP/CodeCoverage/Filter.php' (include_path='.:/usr/share/php:/usr/share/pear') in /usr/bin/phpunit on line 39
更新 chanel 和 pear,來自 Debian 和 ubuntu 社群的方法。測試可用
sudo apt-get remove phpunit
sudo pear channel-discover pear.phpunit.de
sudo pear channel-discover pear.symfony-project.com
sudo pear channel-discover components.ez.no
sudo pear update-channels
sudo pear upgrade-all
sudo pear install --alldeps phpunit/PHPUnit