Home | 简体中文 | 繁体中文 | 杂文 | Search | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 作品与服务 | Email

6.5. PHPUnit - Unit testing framework for PHP

https://phpunit.de/

6.5.1. 安装

6.5.1.1. 使用 pear 安装

查找 phpunit

# pear search PHPUnit
Retrieving data...0%
.Matched packages, channel pear.php.net:
=======================================
Package  Stable/(Latest) Local
PHPUnit  1.3.2 (stable)        Regression testing framework for unit tests.
PHPUnit2 2.3.6 (stable)        Regression testing framework for unit tests.			
			

安装 PHPUnit2

过程 6.1. PHPUnit2

  1. install

    pear install PHPUnit2
    					
  2. phpunit your.php

由于 PHPUnit2 之后 pear 库就没有再更新过,建议采用 phar 方案

6.5.1.2. phar 安装

手工安装

wget https://phar.phpunit.de/phpunit.phar
chmod +x phpunit.phar
mv phpunit.phar /usr/local/bin/phpunit
phpunit --version
			

6.5.1.3. 测试安装是否正确

测试代码

			
# cat test.php
<?php

class Test extends PHPUnit_Framework_TestCase
{
  function test1() { $this->assertTrue( 1 + 2  == 3 ); }
  function test2() { $this->assertTrue( 1 + 1  == 2 ); }
}
?>
			
			

运行测试脚本

# phpunit test.php
PHPUnit 3.7.32 by Sebastian Bergmann.

..

Time: 40 ms, Memory: 2.50Mb

OK (2 tests, 2 assertions)
			
comments powered by Disqus