ubuntu 12.04 安装phpUnit
2013-02-25 16:43
399 查看
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 社区的方法。测试可用
root@ubuntu:~# pear channel-discover pear.phpunit.de
root@ubuntu:~# pear channel-discover pear.symfony-project.com
root@ubuntu:~# pear channel-discover components.ez.no
root@ubuntu:~# pear update-channels
root@ubuntu:sudo pear upgrade-all
root@ubuntu:sudo pear install --alldeps phpunit/PHPUnit //这个可以省略
root@ubuntu:~# sudo pear install --force --alldeps phpunit/PHPUnit
测试:
结果:
成功的测试例子:
解释一个函数:
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 apt-get autoremove apt-get autoclean
root@ubuntu:~# pear channel-discover pear.phpunit.de
root@ubuntu:~# pear channel-discover pear.symfony-project.com
root@ubuntu:~# pear channel-discover components.ez.no
root@ubuntu:~# pear update-channels
root@ubuntu:sudo pear upgrade-all
root@ubuntu:sudo pear install --alldeps phpunit/PHPUnit //这个可以省略
root@ubuntu:~# sudo pear install --force --alldeps phpunit/PHPUnit
成功: root@ubuntu:~# phpunit PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/ming.ini on l ine 1 in Unknown on line 0 PHPUnit 3.7.14 by Sebastian Bergmann.
测试:
class DependencyFailureTest extends PHPUnit_Framework_TestCase { public function testOne() { $this->assertTrue(FALSE); } /** * @depends testOne */ public function testTwo() { } }
结果:
root@ubuntu:~# phpunit /home/beyourself/myphp/phpinfo.php PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/ming.ini on line 1 in Unknown on line 0 PHPUnit 3.7.14 by Sebastian Bergmann. FS Time: 0 seconds, Memory: 2.50Mb There was 1 failure: 1) DependencyFailureTest::testOne Failed asserting that false is true. /home/beyourself/myphp/phpinfo.php:24 FAILURES! Tests: 1, Assertions: 1, Failures: 1, Skipped: 1.
成功的测试例子:
<?php class ExpectedErrorTest extends PHPUnit_Framework_TestCase { /** * @expectedException PHPUnit_Framework_Error */ public function testFailingInclude() { include 'not_existing_file.php'; } } ?> 结果: phpunit ExpectedErrorTest PHPUnit 3.7.0 by Sebastian Bergmann. . Time: 0 seconds, Memory: 5.25Mb OK (1 test, 1 assertion)
解释一个函数:
1. 1 class ArrayHasKeyTest extends PHPUnit_Framework_TestCase { public function testFailure() { $this->assertArrayHasKey('foo', array('ave' => 'baz')); } }
assertArrayHasKey($key,$array) Reports an error identified by [code]$messageif
$arraydoes not have the
$key.[/code]
1 root@ubuntu:~# phpunit /home/beyourself/myphp/phpinfo.php PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/ming.ini on line 1 in Unknown on line 0 PHPUnit 3.7.14 by Sebastian Bergmann. F Time: 0 seconds, Memory: 2.50Mb There was 1 failure: 1) ArrayHasKeyTest::testFailure Failed asserting that an array has the key 'foo'. /home/beyourself/myphp/phpinfo.php:36 FAILURES! Tests: 1, Assertions: 1, Failures: 1.
二// 1 class ArrayHasKeyTest extends PHPUnit_Framework_TestCase 2 { 3 public function testFailure() 4 { 5 $this->assertArrayHasKey('foo', array('foo' => 'baz')); 6 } 7 }
root@ubuntu:~# phpunit /home/beyourself/myphp/phpinfo.php PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/ming.ini on line 1 in Unknown on line 0 PHPUnit 3.7.14 by Sebastian Bergmann. . Time: 0 seconds, Memory: 2.50Mb OK (1 test, 1 assertion)
相关文章推荐
- Ubuntu 12.04 安装 Apache2+PHP5+MySQL
- Ubuntu 12.04上安装Nginx, PHP,Mysql及配置
- Ubuntu 12.04 下 php 安装 imageMagick 扩展
- ubuntu 12.04安装php的权限配制
- ubuntu 12.04 安装 nginx+php+mysql web服务器
- ubuntu 12.04 安装 nginx+php+mysql web服务器
- ubuntu 12.04 安装 Nginx+PHP5 (PHP-FPM) 配置CI项目
- Ubuntu 12.04 + nginx + php5 + php-fpm安装,并进行多站点配置
- ubuntu 12.04 编译安装nginx,php,mysql
- [今日记录] PHP安装 & wordpress部署, Nginx 1.7.3, Ubuntu 12.04
- ubuntu 12.04 PHP5.4安装
- ubuntu 12.04 安装 nginx+php+mysql web服务器
- Ubuntu 12.04上安装APC (php的缓存引擎)
- ubuntu 安装 PHPUnit
- ubuntu 12.04下的nginx+php安装和配置
- centos 6.2 ubuntu 12.04 上安装apache(httpd2.4) nginx1.2 php5.3.10 mysql5.3
- ubuntu 12.04 安装 Nginx+PHP5 (PHP-FPM) +MySQL主机详解
- Ubuntu 12.04 编译安装 PHP 5.4.3
- Ubuntu 12.04 LTS 下安装apache+php+mysql+phpmyadmin
- ubuntu 12.04 安装 nginx+php+mysql web服务器