79

I recently installed phpunit on my server via the pear installer.

When I go to run a test I get the following error:

PHP Warning: require_once(PHPUnit/Util/Filter.php): failed to open stream: No such file or directory in /usr/bin/phpunit on line 44

PHP Fatal error: require_once(): Failed opening required 'PHPUnit/Util/Filter.php' (include_path='.:/usr/bin/php') in /usr/bin/phpunit on line 44

After doing some searching, I tried making some modifications to the include_path in my php.ini file on the server. But that hasn't done a thing.

Any idea what might be causing this?

Community
  • 1
  • 1
user185305
  • 821
  • 1
  • 6
  • 4

17 Answers17

123

UPDATE: As of 2013 November and Ubuntu 12.04 these 2 commands should suffice:

sudo pear config-set auto_discover 1
sudo pear install pear.phpunit.de/PHPUnit

The following is an older answer. It's a known problem , although almost a year and a half had passed. Read about it here

The code coverage must be installed in order for phpunit to work properly

What you need to do is covered here:

code coverage installation through PEAR

Basically you have to type (with sudo if you don't have permissions, taken that phpunit is already installed):

pear channel-discover pear.phpunit.de
pear channel-discover components.ez.no
pear install phpunit/PHP_CodeCoverage
arunas_t
  • 1,576
  • 1
  • 10
  • 14
  • i'm getting `ERROR: Unknown Role class: "PEAR_Installer_Role_Pear_Installer_role_php" ERROR: Unknown Role class: "PEAR_Installer_Role_Pear_Installer_role_data"` error on last step. – Eray Jun 16 '11 at 15:50
  • I just did this and all 3 failed saying they were all already done. Still getting the same error as the OP. – KOGI Jun 21 '11 at 18:47
  • 6
    The correct solution for me was in the first link you gave: https://bugs.launchpad.net/ubuntu/+source/phpunit/+bug/701544/comments/6 – EnigmaCurry Jun 21 '11 at 20:20
  • Im in the same boat as KOGI, no luck as i installed PHPUnit with --alldeps and codecoverage is definitely installed – Marc Towler Jun 25 '11 at 17:42
  • 2
    I had to set the include_path in **both** php.ini files, `/etc/php5/apache2/php.ini`, `/etc/php5/cli/php.ini`, and had to make it include parent and subdirectories: `include_path = ".:/usr/share/php:/usr/share/php/PEAR"` – hobs Aug 01 '11 at 09:19
  • @user185305, I had this same problem and its fixed by following EnigmaCurry's link. – Paulraj Sep 01 '11 at 14:04
  • Just a note - I did not use the last step in EnigmaCurry's link. There is a version mismatch between the current PHPUnit and current CodeCoverage so installing with apt-get breaks PHPUnit (error around a missing getInstance() method). Installing with pear works fine on my box. – Andy Mar 14 '12 at 06:18
  • 7
    On Ubuntu 12.04, I had to also enter `sudo pear channel-discover pear.symfony.com` and then succeeded with `sudo pear install --alldeps phpunit/PHPUnit` – skierpage Sep 21 '12 at 04:47
  • Does not do anything fixed the problem by updating the php.ini path to include the location where phpunit is installed, as detailed in jeroen answer. – MrDaniel Nov 15 '13 at 05:07
  • 2
    Take note! `You have installed PHPUnit via PEAR. This installation method is no longer supported and http://pear.phpunit.de/ will be shut down no later than December, 31 2014. ` ...which will invalidate this answer. – Madbreaks Sep 17 '14 at 17:42
  • Am I the only one who receives "unknown channel "pear.phpunit.de" in "pear.phpunit.de/PHPUnit"" error? Ubuntu 12.04 – Tamara Oct 27 '15 at 19:47
34

I had this problem on OS X. Fixed it with the following commands which force all the php dependencies to be reinstalled, which included a couple of packages from other channels that were not already configured:

sudo pear channel-discover pear.symfony-project.com
sudo pear channel-discover components.ez.no
sudo pear install --alldeps phpunit/PHPUnit
Steven Green
  • 981
  • 8
  • 15
  • This is the only solution that worked for me in Ubuntu 11.10. – mpen Jan 24 '12 at 17:02
  • 4
    Nvm. It installed fine, but when I try to run any actual tests I get `PHP Fatal error: Call to undefined method PHP_CodeCoverage_Filter::getInstance() in /usr/share/php/PHPUnit/Framework.php on line 46` – mpen Jan 24 '12 at 17:21
  • 2
    For me, I did this and then got an error that I think is resolved by http://stackoverflow.com/a/9186866/470749 Ubuntu 12.04 – Ryan Jun 15 '12 at 20:49
  • 1
    Didn't work for me -- I need to `channel-discover pear.phpunit.de` to be able to install phpunit/phpunit, and then I get the `require_once(PHPUnit/Util/Filter.php)` error... the file is nowhere on my filessystem. – ashgromnies Mar 19 '14 at 14:54
  • Take note! `You have installed PHPUnit via PEAR. This installation method is no longer supported and http://pear.phpunit.de/ will be shut down no later than December, 31 2014.` ...which will invalidate this answer. – Madbreaks Sep 17 '14 at 17:43
13

https://bugs.launchpad.net/ubuntu/+source/phpunit/+bug/701544

and specially this comment for ubuntu 11.04 and may be for some others too

even though i did ths steps as recommended above, i didn't get it to work but after i upgraded pear from 1.9.1 to 1.9.2 it's working perfectly just do this

speshu@speshu-laptop:~$ sudo pear upgrade pear

   downloading PEAR-1.9.2.tgz ...
   Starting to download PEAR-1.9.2.tgz (295,120 bytes)
    .....................................................done: 295,120 bytes
    upgrade ok: channel://pear.php.net/PEAR-1.9.2
    PEAR: Optional feature webinstaller available (PEAR's web-based installer)
    PEAR: Optional feature gtkinstaller available (PEAR's PHP-GTK-based installer)
    PEAR: Optional feature gtk2installer available (PEAR's PHP-GTK2-based installer)
    PEAR: To install optional features use "pear install pear/PEAR#featurename"
jspeshu
  • 1,211
  • 3
  • 12
  • 20
  • I did this as soon as I installed PHPUnit and still got the error, but @StevenGreen 's answer helped me =) but it's ok you point it out =) – Metafaniel May 30 '12 at 19:28
8

If it is the first time you are using PEAR, perhaps you have not configured the include path right. Take a look at the appropriate section in the PEAR manual.

jeroen
  • 91,079
  • 21
  • 114
  • 132
4

https://github.com/sebastianbergmann/php-code-coverage

sb@ubuntu ~ % pear channel-discover pear.phpunit.de
Adding Channel "pear.phpunit.de" succeeded
Discovery of channel "pear.phpunit.de" succeeded

sb@ubuntu ~ % pear channel-discover components.ez.no
Adding Channel "components.ez.no" succeeded
Discovery of channel "components.ez.no" succeeded

sb@vmware ~ % pear install phpunit/PHP_CodeCoverage
downloading PHP_CodeCoverage-0.9.0.tgz ...
Starting to download PHP_CodeCoverage-0.9.0.tgz (108,376 bytes)
.........................done: 108,376 bytes
install ok: channel://pear.phpunit.de/PHP_CodeCoverage-0.9.0
Mike
  • 7,769
  • 13
  • 57
  • 81
2

(include_path='.:/usr/bin/php')

Are you sure you added it to the include_path?

It might also help if we saw your ini file, and the include_path snippet in it...

meder omuraliev
  • 183,342
  • 71
  • 393
  • 434
2

I found it!

Looks like PEAR installed PHPUnit in /usr/share/pear. Not sure why but that's where it is. Must be a (mt) thing.

Anyway, I'm all set. Thanks for the help.

user185305
  • 821
  • 1
  • 6
  • 4
2

This is also what happens if you have an out-of-date or incomplete PHPUnit install. Please be aware that after you set up PEAR, you must add the PHPUnit.de channel in order to get an up-to-date package.

Josh Koenig
  • 399
  • 3
  • 8
2

In my case, I solved it by adding /usr/share/php/PEAR to the include_path.

I'm using Ubuntu 10.04.2.

C. Ross
  • 31,137
  • 42
  • 147
  • 238
Marcelo
  • 21
  • 1
1

If you have problems with accessing components try another way.

  1. Install pear

    sudo apt-get install php-pear
    
  2. Install phpunit by using pear.

    pear config-set auto_discover 1
    pear install pear.phpunit.de/PHPUnit
    
  3. Install phpunit/Selenium, but first you need to install curl module

    sudo apt-get install php5-curl 
    pear install phpunit/PHPUnit_Selenium
    
Yi Jiang
  • 49,435
  • 16
  • 136
  • 136
denz
  • 11
  • 1
0

I had this problem . I was developing a zend framework site. Finally I manage to solve it by removing the zend installation and removing/commenting the include path in bath php.ini files in apache and cli. To develop site with zend we don't need to have zend installed. Insted we can copy the library to our site folder

Ruwantha
  • 2,603
  • 5
  • 30
  • 44
0

For me dividing test's in multiple batches helped.

amitchhajer
  • 12,492
  • 6
  • 40
  • 53
0

You can solve this issue by redefining the environment variables in PEAR. This is how I solved the problem and I used Ubuntu 12.10

http://rkrants.blogspot.in/2013/01/installing-phpunitpear-in-ubuntu-1210.html

In short it defines the paths and then reinstalls phpunit

Rabimba Karanjai
  • 186
  • 2
  • 5
  • 14
0

Ubuntu 12.04:

sudo pear channel-discover pear.symfony.com
sudo pear install --alldeps phpunit/PHPUnit
RBalazs
  • 25
  • 4
0

I had the same issue with Windows 8 Similar to the top answer, I needed to start the command line, however make sure to run cmd.exe as administrator. Then the two commands

pear config-set auto_discover 1
pear install pear.phpunit.de/PHPUnit
Moak
  • 12,596
  • 27
  • 111
  • 166
0

I was having the same problem. Netbeans was reporting that the phpunit version was too old (which it wasn't). Running the phpunit script directly showed the above messages.

I solved it adding:

include_path=".:/usr/share/php"

To /etc/php5/cli/php.ini

Please NOTE that the php.ini file is the one for php CLI (command) not the php.ini used for apache!

lepe
  • 24,677
  • 9
  • 99
  • 108
0

My original problem was I could not get the command line version of php (yum install php or yum install php-cli) to upgrade to => php5.2.7 I was stuck on 5.1 version

I had already compiled php 5.3.3 for use with apache. So I setup a symbolic link from /usr/bin/php (the command line default) to my compiled version in /var/php5/bin/php to get the command line php reporting 5.3.3

Then I refollowed the pear install steps for phpunit

But it still needed the code coverage stuff when I ran phpunit.

So I hunted code coverage down under /var/php5/lib/php/PHP/CodeCoverage and added that to the include path in php.ini include_path=".:/var/php5/lib/php/"

Make sure to add it to the include path without /PHP because phpunit starts at PHP/ (notice caps) looking for Code Coverage Failed opening required 'PHP/CodeCoverage/Filter.php'