Error when running PHPUnit

蓝咒 提交于 2019-12-05 07:34:45

you can try this, I have done it on my Ubuntu 12.04

  1. sudo pear uninstall phpunit/PHPUnit
  2. sudo pear uninstall pear.phpunit.de/PHPUnit_MockObject
  3. sudo pear install pear.phpunit.de/PHPUnit_MockObject
  4. sudo pear install --alldeps pear.phpunit.de/PHPUnit

I have tried many other methods. This works when I get the error blow.

hegaofeng@ubuntu:~$ 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 hegaofeng@ubuntu:~$ cd /usr/share/php/

I've had issues when not using the actual pear.phpunit.de channel to install PHPUnit, especially when trying to use a package manager like apt-get or yum. Try removing all the manually installed stuff you pulled from the git repository and do a pear uninstall of PHPUnit and its optional dependencies. Then:

  • sudo pear upgrade PEAR
  • sudo pear config-set auto_discover 1
  • sudo pear install --alldeps pear.phpunit.de/PHPUnit

This has worked for me ... hope it helps.


UPDATE

It probably goes without saying, but you should also purge your previous apt-get attempts as well before following the steps above:

  • sudo apt-get purge php5-pear

Manual Installation for 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

Add the following to your 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

Open /usr/share/php/PHPUnit/Framework.php and you will see this:

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

That's all! Please no longer include "PHPUnit/Framework.php"!!!

Before installing PHPUnit on your system, clear pear's cache

pear clear-cache

From what i have seen, maybe you haven't integrated PHPUnit with your project. You don't need to only install PHPUnit using PEAR, i believe the files you need are not in the project.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!