Unfortunately, PHPUnit does not work out of the box on Ubuntu 11.04 through apt-get. We also need to use PEAR to install the dependencies.
The Problem
The standard approach is to simply use apt-get or pear to install everything:
$ sudo apt-get install phpunit
After installing the package, you will most likely receive the following error:
PHP Fatal error: require_once(): Failed opening required 'PHP/CodeCoverage/Filter.php' (include_path='.:/usr/share/php:/usr/share/pear') in /usr/bin/phpunit on line 38
Installing Dependencies
Obviously, we’re missing a few dependencies as shown in the previous error. Fortunately, PEAR provides the --alldeps flag while installing so that we automatically download and install dependencies that are necessary.
Upgrade PEAR First
There’s one more problem: Ubuntu 11.04 comes with PEAR version 1.9.1 when we need version 1.9.2 for all dependencies to install. Before we go any further, we need to upgrade PEAR:
$ sudo pear upgrade pear
Install PHPUnit Dependencies
Now, we can install PHPUnit and it’s dependencies through PEAR.
$ sudo pear channel-discover pear.phpunit.de
$ sudo pear channel-discover components.ez.no
$ sudo pear channel-discover pear.symfony-project.com
$ sudo pear install --alldeps phpunit/PHPUnit
Make Sure It Works
After everything is complete, verify that phpunit works:
$ phpunit --version
PHPUnit 3.5.5 by Sebastian Bergmann.
Have fun unit testing with PHPUnit.
21 Comments
Thank you for this! This has been a thorn in my side for weeks.
Thanks! Great tutorial.
- @jdorfman
This works flawlessly, thank you
Thanks for you! Finally the working tutorials
It won’t work.
Still the same :
PHP Fatal error: require_once(): Failed opening required ‘PHP/CodeCoverage/Filter.php’ (…)
Both the PEAR and PHPUnit paths are properly det in the include_path but it’s just as if PHPUnit ignores it.
It won’t work.
if u know right syntax then please sent email i wait for you result….
If you get this error:
Failed to download pear/HTTP_Request2 within preferred state “stable”, latest release is version 2.0.0RC1, stability “beta”, use “channel://pear.php.net/HTTP_Request2-2.0.0RC1″ to install
Do this instead of the last command:
sudo pear install –alldeps phpunit/PHPUnit-beta
It’s a weird pear thing with versioning.
Thank-you for documenting this – it saved me a fair amount of time.
Thanks for this tutorial.
For reference,
sudo apt-get install phpunitstill doesn’t work properly in Ubuntu 11.10 (oneiric).Here’s the code from this walkthrough as a bash file, for convenience:
https://gist.github.com/1252336
thank you, it works!
I am getting this error
PHP Warning: require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in /usr/share/php/PHPUnit/Autoload.php on line 45
PHP Fatal error: require_once(): Failed opening required ‘File/Iterator/Autoload.php’ (include_path=’/usr/share/php/libzend-framework-php’) in /usr/share/php/PHPUnit/Autoload.php on line 45
an ideas?
I got an error like this one too
PHP Warning: require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in /usr/share/php/PHPUnit/Autoload.php on line 45
PHP Fatal error: require_once(): Failed opening required ‘File/Iterator/Autoload.php’ (include_path=’/usr/share/php/libzend-framework-php’) in /usr/share/php/PHPUnit/Autoload.php on line 45
It requires the File library which is outside of the PHPUnit folder so i made a copy of File folder and placed it inside PHPUnit location and it worked smooth
still does not work, struggling with
PHP Fatal error: Call to undefined method PHP_CodeCoverage_Filter::getInstance() in /usr/bin/phpunit on line 39
any ideas?
I forgot to mention I’m on Ubuntu 11.10
Thanks guy, worked perfectly.
ty
Excelente….
Thanks, its helped me lot.
This is greate , works well
Thanks, can i translate your tutorial to my blog?
Sure.
One Trackback
[...] http://www.giocc.com/installing-phpunit-on-ubuntu-11-04-natty-narwhal.html [...]