Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPUnit: Warning: require(PHPUnit/Autoload.php): failed to open stream: No such file or directory in /usr/local/bin/phpunit on line 42

when running

  • phpunit

I get error

Warning: require(PHPUnit/Autoload.php): failed to open stream: No such file or directory in /usr/local/bin/phpunit on line 42

Fatal error: require(): Failed opening required 'PHPUnit/Autoload.php' (include_path='.:') in /usr/local/bin/phpunit on line 42

/usr/local/bin/phpunit displays the following on line 42:

require 'PHPUnit/Autoload.php';

any suggestions how to fix this?

Update (1):

I was missing php.ini in /etc/, so I symlinked it to read the MAMP php.ini. Now I get

php -r 'foreach (explode(":", get_include_path()) as $path) echo $path . PHP_EOL;'
.
/Applications/MAMP/bin/php/php5.3.6/lib/php
/usr/local/bin/pear
/usr/local/share/pear/PHPUnit

running

  • phpunit

is running but provides no output.

Any suggestions what to check next?

Update (2):

probably the root cause of this issue is related to question

  • MAMP PEAR configuration is pointing to local directories.
like image 664
udo Avatar asked Nov 30 '11 21:11

udo


4 Answers

I hit a similar issue on MAC OSX Lion. I installed phpunit with the PEAR package manager, and when I try to run it I got the error as described by udo. I was able to resolve it with the following simple steps:

  1. Get the latest php archive of pear curl http://pear.php.net/go-pear.phar > go-pear.php
  2. Install the archive with sudo php -q go-pear.php

During installation, it detects if the include_path in your php.ini does not contain the PEAR PHP directory. You can choose to let it fix it for you automatically when given the option.

like image 83
warhod Avatar answered Oct 19 '22 23:10

warhod


I ran into this problem when I was running phpunit.phar from my local directory, but also has PHPUnit installed as a composer dependency. Removing the PHPUnit composer dependency fixed my problem.

like image 34
edan Avatar answered Oct 19 '22 23:10

edan


You must have the folder that contains the PHPUnit source files on your PHP include path. Also, PHPUnit/Autoload.php was added in 3.6, and it's possible you have an older 3.5.x source folder instead. Check the folders listed using

php -r 'foreach (explode(':', get_include_path()) as $path) echo $path . PHP_EOL;'

(or on Windows)

php -r"foreach (explode(':', get_include_path()) as $path) echo $path . PHP_EOL;"

and make sure one of them contains a PHPUnit folder with Autoload.php.

Update: Regarding your update, you probably want to remove /usr/local/share/pear/PHPUnit from the include path because you're including PHPUnit/Autoload.php which should be located in /usr/local/share/pear which is already in the include path.

To make sure PHPUnit is working first run phpunit --version so you can see the installed version. PHPUnit instantiates all of the test cases it plans to run before outputting anything. If any of your test cases cause a fatal error while loading, sometimes no output is shown at all. This is very frustrating. Start by creating the simplest test case possible that doesn't use any of your code.

class MyTest extends PHPUnit_Framework_TestCase {
    function testThatItWorks() {
        self::assertTrue(true);
    }
}

Running this test should produce a single passing test. Try it and paste what you see in your question.

like image 5
David Harkness Avatar answered Oct 19 '22 23:10

David Harkness


To add to the previous answers: double-check with php.ini file is being loaded and make sure you edit THAT file with additional paths. I used the following to check the loaded php.ini

php -r 'phpinfo();'

Which told me that the loaded php.ini file was /private/etc/php.ini

Then I used "which" to tell me where phpunit had been installed:

which phpunit

Then I added that path to the php.ini file, so it ended up looking like this:

;***** Added by go-pear
include_path=".:/Users/admin/pear/share/pear:/php/includes:/usr/bin:/usr/lib/php/"

Only after I had done all that did the "phpunit --version" and other commands work as expected.

like image 3
Everett Avatar answered Oct 19 '22 23:10

Everett