Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
运行PHPUnit时出错_Php_Unit Testing_Phpunit_Ubuntu 11.10 - Fatal编程技术网

运行PHPUnit时出错

运行PHPUnit时出错,php,unit-testing,phpunit,ubuntu-11.10,Php,Unit Testing,Phpunit,Ubuntu 11.10,当我尝试从项目的测试文件夹中运行phpunit.时,出现以下错误: PHP Fatal error: Call to undefined method PHP_CodeCoverage_Filter::getInstance() in /usr/share/php/PHPUnit/Framework.php on line 46 我通过以下命令安装了PHPUnit: sudo pear channel-discover pear.symfony-project.com sudo pear c

当我尝试从项目的测试文件夹中运行
phpunit.
时,出现以下错误:

PHP Fatal error:  Call to undefined method PHP_CodeCoverage_Filter::getInstance() in /usr/share/php/PHPUnit/Framework.php on line 46
我通过以下命令安装了PHPUnit:

sudo pear channel-discover pear.symfony-project.com
sudo pear channel-discover components.ez.no
sudo pear install --alldeps phpunit/PHPUnit
sudo apt-get install git
mkdir phpunit && cd phpunit
git clone git://github.com/sebastianbergmann/phpunit.git
git clone git://github.com/sebastianbergmann/dbunit.git
git clone git://github.com/sebastianbergmann/php-file-iterator.git
git clone git://github.com/sebastianbergmann/php-text-template.git
git clone git://github.com/sebastianbergmann/php-code-coverage.git
git clone git://github.com/sebastianbergmann/php-token-stream.git
git clone git://github.com/sebastianbergmann/php-timer.git
git clone git://github.com/sebastianbergmann/phpunit-mock-objects.git
git clone git://github.com/sebastianbergmann/phpunit-selenium.git
git clone git://github.com/sebastianbergmann/phpunit-story.git
git clone git://github.com/sebastianbergmann/php-invoker.git
sudo cp -r dbunit/PHPUnit /usr/share/php/
sudo cp -r php-code-coverage/PHP /usr/share/php/
sudo cp -r php-file-iterator/File /usr/share/php/
sudo cp -r php-invoker/PHP /usr/share/php/
sudo cp -r php-text-template/Text /usr/share/php/
sudo cp -r php-timer/PHP /usr/share/php/
sudo cp -r php-token-stream/PHP /usr/share/php/
sudo cp -r phpunit/PHPUnit /usr/share/php/
sudo cp -r phpunit-mock-objects/PHPUnit /usr/share/php/
sudo cp -r phpunit-selenium/PHPUnit /usr/share/php/
sudo cp -r phpunit-story/PHPUnit /usr/share/php/
sudo cp -r phpunit/phpunit.php /usr/share/php/
因为其他方法似乎都不起作用,包括
apt-get

我认为CodeCoverage在某个时间点改变了他们的单例模式,因此删除了
getInstance
,但我不知道如何修复这个错误。如何降级CodeCoverage或升级PHPUnit

我尝试通过以下命令手动安装所有内容的最新版本:

sudo pear channel-discover pear.symfony-project.com
sudo pear channel-discover components.ez.no
sudo pear install --alldeps phpunit/PHPUnit
sudo apt-get install git
mkdir phpunit && cd phpunit
git clone git://github.com/sebastianbergmann/phpunit.git
git clone git://github.com/sebastianbergmann/dbunit.git
git clone git://github.com/sebastianbergmann/php-file-iterator.git
git clone git://github.com/sebastianbergmann/php-text-template.git
git clone git://github.com/sebastianbergmann/php-code-coverage.git
git clone git://github.com/sebastianbergmann/php-token-stream.git
git clone git://github.com/sebastianbergmann/php-timer.git
git clone git://github.com/sebastianbergmann/phpunit-mock-objects.git
git clone git://github.com/sebastianbergmann/phpunit-selenium.git
git clone git://github.com/sebastianbergmann/phpunit-story.git
git clone git://github.com/sebastianbergmann/php-invoker.git
sudo cp -r dbunit/PHPUnit /usr/share/php/
sudo cp -r php-code-coverage/PHP /usr/share/php/
sudo cp -r php-file-iterator/File /usr/share/php/
sudo cp -r php-invoker/PHP /usr/share/php/
sudo cp -r php-text-template/Text /usr/share/php/
sudo cp -r php-timer/PHP /usr/share/php/
sudo cp -r php-token-stream/PHP /usr/share/php/
sudo cp -r phpunit/PHPUnit /usr/share/php/
sudo cp -r phpunit-mock-objects/PHPUnit /usr/share/php/
sudo cp -r phpunit-selenium/PHPUnit /usr/share/php/
sudo cp -r phpunit-story/PHPUnit /usr/share/php/
sudo cp -r phpunit/phpunit.php /usr/share/php/
但这没有任何帮助。现在我到处都是垃圾:\


版本信息:

PEAR Version: 1.9.4
PHP Version: 5.3.6-13ubuntu3.3
Zend Engine Version: 2.3.0
PHPUnit 3.6.9 by Sebastian Bergmann.


我在不使用实际的
pear.phpunit.de
通道安装phpunit时遇到问题,尤其是在尝试使用apt-get或yum之类的包管理器时。尝试从git存储库中删除所有手动安装的内容,并对PHPUnit及其可选依赖项执行
pear卸载。然后:

  • 水梨
  • sudo pear配置集自动搜索1
  • sudopear安装——alldeps pear.phpunit.de/phpunit
这对我很有用。。。希望能有帮助


更新

可能不用说,但在执行上述步骤之前,您还应该清除以前的apt get尝试:

  • sudo容易得到净化php5梨
Ubuntu 11.10的手动安装 将以下内容添加到您的
包含路径中

/usr/share/php/dbunit:/usr/share/php/php-code-coverage:/usr/share/php/php-file-iterator:/usr/share/php/php-text-template:/usr/share/php/php-timer:/usr/share/php/php-token-stream:/usr/share/php/phpunit:/usr/share/php/phpunit-mock-objects:/usr/share/php/phpunit-selenium:/usr/share/php/phpunit-story:/usr/share/php/php-invoker

你可以试试这个,我已经在我的Ubuntu 12.04上完成了

  • sudopear卸载phpunit/phpunit
  • sudo pear卸载pear.phpunit.de/phpunit\u MockObject
  • sudopear安装pear.phpunit.de/phpunit\u MockObject
  • sudopear安装——alldeps pear.phpunit.de/phpunit
  • 我尝试过许多其他方法。当我受到错误打击时,这就起作用了

    hegaofeng@ubuntu:~$phpunit PHP警告:require_once(PHPUnit/Framework/MockObject/Autoload.PHP):无法打开>?>流:第48行的/usr/share/PHP/PHPUnit/Autoload.PHP中没有这样的文件或目录 PHP致命错误:require_once():无法在>第48行的/usr/share/PHP/PHPUnit/Autoload.PHP中打开required>'PHPUnit/Framework/MockObject/Autoload.PHP'>(include_path='。:/usr/share/PHP:/usr/share/pear') hegaofeng@ubuntu:~$cd/usr/share/php/


    打开/usr/share/php/PHPUnit/Framework.php,您将看到:

    trigger_error(
        'Please no longer include "PHPUnit/Framework.php".', E_USER_NOTICE
    );
    

    就这些请不要再包含“PHPUnit/Framework.php”

    在系统上安装PHPUnit之前,请清除pear的缓存

    pear clear-cache
    

    据我所见,也许你还没有将PHPUnit与你的项目整合在一起。你不需要只使用PEAR安装PHPUnit,我相信你需要的文件不在项目中。

    我也无法让PHPUnit在Ubuntu11.10上为我工作。我也有同样的问题,我已经以50分的悬赏要求它:作为PEAR的对手记录在案,以及PHPUnit在当前状态下发布的方式。@MikePurcell:我们没有太多的单元测试替代方案,是吗?易于安装且相对易于使用的?这个项目到目前为止只有2个单元测试…所以我们仍然可以切换@马克:好的,完成了本文的v1.0版,看一看,告诉我它是否适合你。祝你好运(获得50分奖励)好吧,这给我编了一个不同的错误:
    PHP致命错误:require_once():无法打开所需的“PHPUnit/Framework/MockObject/Autoload.PHP”
    “MockObject”目录不存在。有趣的你可能认为“alldeps”会安装所有的deps。显然不是。我怎么找回MockObjects?差点忘了--我也有同样的问题。我相信正确的命令是:
    pear install phpunit/phpunit\u MockObject
    。让我知道这是否正确。哎呀,我想应该是
    pear install pear.phpunit.de/phpunit\u MockObject
    pear install phpunit/phpunit\u MockObject
    失败并显示“已安装”消息…但文件夹不在那里..hrm。好啊卸载并重新安装,现在安装了模拟对象,但现在打开所需的“PHPUnit/Framework.php”
    失败。有一个Framework文件夹,但没有Framework.php