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.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.
37 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?
Have you solved the phpunit installation problem?
I get the same issue now.
Just take a look at http://stackoverflow.com/questions/9186000/call-to-undefined-method-php-codecoverage-filtergetinstance at the Anthony’s reply…
This fixed for me, either on 12.04.
sudo apt-get remove phpunit
sudo pear channel-discover pear.phpunit.de
sudo pear channel-discover pear.symfony-project.com
sudo pear channel-discover components.ez.no
sudo pear update-channels
sudo pear upgrade-all
sudo pear install –alldeps phpunit/PHPUnit
sudo pear install –force –alldeps phpunit/PHPUnit
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.
Yet another big thank you!
Thanks! Great Tutorial!!
Very clean and straight forward tutorial. Thanks
Well done, thanks.
you are the man
Thanks, This was doing my head in
This is an excellent and concise guide.
I owe you a cold drink if you ever visit spain…
des
Great tutorial.
Just a comment, I needed to added the following channel as well in my Ubuntu: 12.04
sudo pear channel-discover pear.symfony.com
Gr8 post, however, you should change”
sudo pear channel-discover pear.symfony-project.com
to
sudo pear channel-discover pear.symfony.com.
Nice tut.
Great job!
Great tutorial, thanx
hey Dud, Thanks for your Guide .
for folks that the above guide did not work, try doing this on top of all those commands on the top, it worked for me, also after the installation, i had to check that all my php installation files were intact, they had got messed up, and luckily i could copy them over from a colleague.
sudo pear install –force –alldeps phpunit/PHPUnit
3 Trackbacks
[...] http://www.giocc.com/installing-phpunit-on-ubuntu-11-04-natty-narwhal.html [...]
[...] http://www.giocc.com/installing-phpunit-on-ubuntu-11-04-natty-narwhal.html This entry was posted in Uncategorized by admin. Bookmark the permalink. [...]
[...] All your test cases will go into fuel/app/test . If you do not have phpUnit installed, there are 3 ways you can do that – Pear, Composer or Phar. Since you’d be running tests only on your development machine (I, at least personally see no use of test in a production environment) you can simply install it through Pear. You can find a how-to guide here. [...]