2012-01-24 75 views
6

我收到以下錯誤,當我嘗試我的項目的測試文件夾中運行從phpunit .錯誤運行時,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 

由於沒有任何的其他方法似乎工作,包括apt-get

認爲代碼覆蓋率的時間在某些時候改變了他們的單件模式,從而去除getInstance但我不知道如何解決這個錯誤。我如何降級CodeCoverage或升級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. 

Installed packages, channel pear.phpunit.de: 
============================================ 
Package   Version State 
File_Iterator  1.3.1 stable 
PHPUnit   3.6.9 stable 
PHPUnit_MockObject 1.1.1 stable 
PHP_CodeCoverage 1.1.1 stable 
PHP_Invoker  1.1.0 stable 
PHP_Timer   1.0.2 stable 
PHP_TokenStream 1.1.2 stable 
Text_Template  1.1.1 stable 
+0

我一直無法在Ubuntu 11.10上讓phpUnit爲我工作。 –

+2

我有同樣的問題,我已經問過** 50點賞金**:http://stackoverflow.com/questions/8949963/phpunit-pear-upgrading-errors – Eray

+0

去記錄作爲PEAR的對手,和PHPUnit是以當前狀態發佈的。 –

回答

5

我沒有使用實際pear.phpunit.de通道時有問題安裝PHPUnit,特別是在嘗試使用像apt-get或yum這樣的包管理器時。嘗試刪除從git存儲庫中提取的所有手動安裝的東西,並執行PHPUnit的pear uninstall及其可選依賴項。然後:

  • 須藤梨梨升級
  • 須藤梨配置設置auto_discover 1
  • 須藤梨安裝--alldeps pear.phpunit.de/PHPUnit

這爲我工作。 .. 希望能幫助到你。


UPDATE

它可能不用說,但你也應該清除以前的apt-get的嘗試,以及之前完成上述步驟:

  • sudo易於得到淨化php5-pear
+0

http://stackoverflow.com/questions/8949963/phpunit-pear-upgrading-errors(** with 50點賞金**) – Eray

+0

那麼代碼我一個不同的錯誤:'PHP致命錯誤:require_once():失敗開放所需'PHPUnit/Framework/MockObject/Autoload.php' – mpen

+0

「MockObject」目錄不存在。滑稽。你會認爲「alldeps」會安裝所有的代碼。顯然不是。我如何獲得MockObjects? – mpen

2

手動安裝Ubuntu 11.10

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 
cd phpunit && git checkout 3.6 && cd .. 
cd dbunit && git checkout 1.1 && cd .. 
cd php-code-coverage && git checkout 1.1 && cd .. 
cd phpunit-mock-objects && git checkout 1.1 && cd .. 
cd phpunit-selenium && git checkout 1.1 && cd .. 
sudo mv ./* /usr/share/php/ 
ln -s /usr/share/php/phpunit/phpunit.php ~/bin/phpunit 
gksudo gedit /etc/php5/cli/php.ini 

以下內容添加到您的include_path

/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 
7

你可以試試這個,我已經做到了我的Ubuntu的12。04

  1. 須藤梨卸載的PHPUnit/PHPUnit的
  2. 須藤梨卸載pear.phpunit.de/PHPUnit_MockObject
  3. 須藤梨安裝pear.phpunit.de/PHPUnit_MockObject
  4. 須藤梨安裝--alldeps梨。 phpunit.de/PHPUnit

我試過很多其他的方法。這在我受到錯誤打擊時起作用。

[email protected]:~$ phpunit PHP Warning: require_once(PHPUnit/Framework/MockObject/Autoload.php): failed to open >?>stream: No such file or directory in /usr/share/php/PHPUnit/Autoload.php on line 48 PHP Fatal error: require_once(): Failed opening required >'PHPUnit/Framework/MockObject/Autoload.php' >(include_path='.:/usr/share/php:/usr/share/pear') in /usr/share/php/PHPUnit/Autoload.php on >line 48 [email protected]:~$ cd /usr/share/php/

1

打開/usr/share/php/PHPUnit/Framework.php,你會看到:

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

這一切! 請不要再包含「PHPUnit/Framework.php」!

1

系統,清晰梨的緩存

pear clear-cache 

上安裝的PHPUnit從我所見過的,也許你沒有PHPUnit的整合與您的項目。您不需要僅使用PEAR安裝PHPUnit,我相信您需要的文件不在項目中。