2010-11-30 168 views
6

我刚开始为我的代码再次创建单元测试。我过去曾经使用过PHPUnit,但今天它并没有打球。在我创建任何新的测试之前,我决定运行一些旧测试,看看它们是否仍然有效,但是我从PHPUnit本身得到一个致命错误。我在Ubuntu中从CLI运行PHPUnit。phpUnit致命错误

phpunit TestCaseFile 

PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/imap.ini on line 1 in Unknown on line 0 
PHP Warning: Xdebug MUST be loaded as a Zend extension in Unknown on line 0 

Warning: Directive 'register_long_arrays' is deprecated in PHP 5.3 and greater in Unknown on line 0 

Warning: Directive 'magic_quotes_gpc' is deprecated in PHP 5.3 and greater in Unknown on line 0 

Fatal error: Class 'PHPUnit_Framework_MockObject_Matcher_InvokedRecorder' not found in /usr/share/php/PHPUnit/Framework/MockObject/Matcher/InvokedAtLeastOnce.php on line 60 

Call Stack: 
    0.0002  651688 1. {main}() /usr/bin/phpunit:0 
    0.0031 1173168 2. require('/usr/share/php/PHPUnit/TextUI/Command.php') /usr/bin/phpunit:48 
    0.0046 1485456 3. require_once('/usr/share/php/PHPUnit/TextUI/TestRunner.php') /usr/share/php/PHPUnit/TextUI/Command.php:47 
    0.0047 1503344 4. require_once('/usr/share/php/PHPUnit/Framework.php') /usr/share/php/PHPUnit/TextUI/TestRunner.php:47 
    0.0168 3848688 5. require('/usr/share/php/PHPUnit/Framework/TestCase.php') /usr/share/php/PHPUnit/Framework.php:68 
    0.0178 4091880 6. require_once('/usr/share/php/PHPUnit/Framework/MockObject/Matcher/InvokedAtLeastOnce.php') /usr/share/php/PHPUnit/Framework/TestCase.php:49 

我检查,以确保存在的文件,该文件路径等都是正确的,但我真的不知道如何去修复它谁能帮助?

回答

3

别担心,我修好了。

原来,当我第一次安装PHPUnit的我用APT安装我跑

apt-get remove phpunit

然后重新安装

apt-get install phpunit

给我弄了最新版本,一切工作正常。希望这可以帮助其他有类似问题的人。

22

我在OSX上遇到了这个麻烦。我不得不通过PEAR删除phpunit,再次添加ez组件通道,然后重新安装phpunit。

$ phpunit 
PHP Fatal error: Class 'PHPUnit_Framework_MockObject_Matcher_InvokedRecorder' not found in /usr/lib/php/PHPUnit/Framework/MockObject/Matcher/InvokedAtLeastOnce.php on line 60 
$ sudo pear uninstall phpunit/PHPUnit 
uninstall ok: channel://pear.phpunit.de/PHPUnit-3.4.11 
$ sudo pear install phpunit/PHPUnit 
Unknown remote channel: components.ez.no 
Unknown remote channel: components.ez.no 
phpunit/PHPUnit can optionally use PHP extension "dbus" 
phpunit/PHP_CodeCoverage requires package "channel://components.ez.no/ConsoleTools" (version >= 1.6) 
phpunit/PHP_CodeCoverage can optionally use PHP extension "xdebug" (version >= 2.0.5) 
phpunit/PHPUnit requires package "phpunit/PHP_CodeCoverage" (version >= 1.0.2) 
phpunit/PHP_TokenStream requires package "channel://components.ez.no/ConsoleTools" (version >= 1.6) 
No valid packages found 
install failed 
$ sudo pear channel-discover components.ez.no 
Adding Channel "components.ez.no" succeeded 
Discovery of channel "components.ez.no" succeeded 
$ sudo pear update-channels 
.... 
$ sudo pear install phpunit/PHPUnit 
phpunit/PHPUnit can optionally use PHP extension "dbus" 
phpunit/PHP_CodeCoverage can optionally use PHP extension "xdebug" (version >= 2.0.5) 
downloading PHPUnit-3.5.10.tgz ... 
.... 
install ok: channel://components.ez.no/Base-1.8 
install ok: channel://components.ez.no/ConsoleTools-1.6.1 
install ok: channel://pear.phpunit.de/PHP_TokenStream-1.0.1 
install ok: channel://pear.phpunit.de/PHP_CodeCoverage-1.0.3 
install ok: channel://pear.phpunit.de/PHPUnit-3.5.10 
$ phpunit 
PHPUnit 3.5.10 by Sebastian Bergmann. 

Sorted。

+1

该修补程序在Windows中工作正常,你只需要删除`sudo`部分:) – 2011-02-18 11:55:08

2

首先我有这个问题:

梨/ XML_RPC2需要PHP扩展 “卷曲”

所以我通过Ubuntu软件中心安装PHP5卷曲。

然后有这样的问题:

未知远程信道:components.ez.no

的依赖,因此不能被安装。这样做了以后:

须藤梨通道发现components.ez.no

一切都只是正常工作。