坑爹的 phpunit

最新的 phpunit 是 3.6 。之前用的是 3.5 。在一个新机器上安装,按官网的方法,装了新版本后,运行,出错!

Call to undefined method PHP_CodeCoverage_Filter::getInstance()

新版本的 CodeCoverage 改变了调用方法。从 phpunit 3.4 升级到 3.5 的时候,CodeCoverage 的使用也发生过改变。这回又来了…… 这次不想改测试代码,于是打算用旧的 PHP_CodeCoverage 。于是

sudo pear install -f http://pear.phpunit.de/get/PHP_CodeCoverage-1.0.5.tgz

结果,还是出错

Class ‘File_Iterator’ not found

看看 pear 的目录里,明明有 File/Iterator.php 啊,再看看那个 Iterator/Factory.php ,里面没有 require。。。 试着加一条

require_once 'File/Iterator.php';

这回 ok 了。不过改代码这事也挺恶心。于是试着把 File_Iterator 也用个旧版本

sudo pear install -f http://pear.phpunit.de/get/File_Iterator-1.2.6.tgz

然后就又 ok 了。

这货为啥总是改接口呢?还不保持向后兼容呢……

4 thoughts on “坑爹的 phpunit

  1. aaron January 17, 2012 / 12:29 am

    确实坑爹,多谢指导!

  2. Don April 22, 2012 / 4:19 pm

    今天也遇到“Call to undefined method PHP_CodeCoverage_Filter::getInstance()”这个报错,我一开始是改的报错的文件,测试可以通过了。
    后来看了下系统的环境变量,发现path里的路径写错了,改成正确的路径然后把前面的修改改回去发现没有报错了~ 有问题的修改前也不妨检查下自己的系统变量是否正确~

    • 神仙 April 22, 2012 / 10:11 pm

      嗯。后来我在自己的机器上也碰到过,后来发现是有两个phpunit。不过那会,那个机器还是是个纯洁的。确实是因为新版phpunit不兼容旧版代码。

  3. 蜗牛仔 June 18, 2012 / 5:13 pm

    今天我也遇到了这样问题,用了你的办法还是用问题,
    PHP Notice: Please no longer include “PHPUnit/Framework.php”. in /usr/share/php/PHPUnit/Framework.php on line 50

    后边在yii的bug查到了,原来把

    //require_once ‘PHPUnit/Framework.php’; 改成

    require_once(‘PHPUnit/Autoload.php’);
    就可以了

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s