27

I am getting this error while i tried to run testclass in phpunit.

C:\xampp\htdocs\unittest>phpunit UnitTest usertest.php
PHP Warning:  require_once(File/Iterator/Autoload.php): failed to open stream No such file or directory in C:\xampp\php\pear\PHPUnit\Autoload.php on line 45
PHP Stack trace:
PHP   1. {main}() C:\xampp\php\phpunit:0
PHP   2. require() C:\xampp\php\phpunit:41

Warning: require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in C:\xampp\php\pear\PHPUnit\Autoload.php on line 45

Call Stack:
    0.0004     325352   1. {main}() C:\xampp\php\phpunit:0
    0.0026     366520   2. require('C:\xampp\php\pear\PHPUnit\Autoload.php')xampp\php\phpunit:41

PHP Fatal error:  require_once(): Failed opening required 'File/Iterator/Autoload.php' (include_path='.;C:\php\pear') in C:\xampp\php\pear\PHPUnit\Autoload.php on line 45
PHP Stack trace:
PHP   1. {main}() C:\xampp\php\phpunit:0'

could anyone give solution to this ??

Note: i am using windows 7.

Thanks,

edorian
  • 38,542
  • 15
  • 125
  • 143
pearlsoft
  • 331
  • 1
  • 4
  • 4
  • *(related)* (fix will work): http://stackoverflow.com/questions/8078707/cannot-get-phpunit-working – edorian Jan 02 '12 at 12:51
  • *(note)* As far as i can tell this is not a duplicate and since it's an installation issue maybe SF migration but it's a real question :) – edorian Jan 02 '12 at 16:01
  • Came across similar error too. Simple fix for this in case you are using composer, make sure you have the latest stable version of PHPUnit, e.g. 5.5, and all will work. – ProfNandaa Sep 18 '16 at 14:35

11 Answers11

23

A possible reason that this might happen is that your php include_path is not set correctly. Please make sure you have the appropriate path to PEAR available. For my WAMP installation it would be:

include_path=".;C:\wamp\bin\php\php5.3.8\PEAR\PEAR"

However, it will most likely be different on your system.

A side note, you will want to update both your apache php.ini, as well as your php.ini located in your PHP installation folder. CLI the default php.ini, and web requests (and often times other software that you might be using PEAR packages for) will use the apache php.ini.

Hope this helps.

Syntaqx
  • 231
  • 1
  • 2
  • 3
    This is exactly what it was for me, though I didn't realise it until I [RTFM](http://pear.php.net/manual/en/installation.checking.php). As a side note, `;` for windows and `:` for osx/unix as the dir seperator. – George May 10 '12 at 10:19
  • Worked for me too. In Ubuntu my path is ".:/usr/share/pear" in case it helps someone. – Tim Seguine Sep 10 '13 at 10:09
  • "Me too" (sorry), in my case it was due to an upgrade of PHP via Mac ports which had installed a new php.ini configuration, but hadn't copied over the go-pear generated include path. – scipilot Jun 20 '16 at 09:19
10

Your phpunit installation is broken. The easiest fix for this is

pear install --force --alldeps phpunit/phpunit

and see if what worked out.

You will need the most current pear version 1.9.4. If you don't have that version install it using the go-pear.phar. If you are running from xammp for something don't try to fix the pear installation they ship. Usually it's a LOT easier to reinstall it.

If you want to you can try to just install the missing package too:

pear install phpunit/File_Iterator

(add a --force if pear tells you that it is already installed)

edorian
  • 38,542
  • 15
  • 125
  • 143
7

Checking pear config helped me find this quicky:

bash-3.2# pear config-show | grep php_dir
PEAR directory                 php_dir          /usr/local/pear/share/pear

bash-3.2# vi /etc/php.ini
include_path = ".:/php/includes:/usr/local/pear/share/pear"
d g
  • 1,594
  • 13
  • 13
  • This method works for me. In Ubuntu 12.04, First find the php_dir, which is "/usr/share/php", then using "locate php.ini" to find its right location. My case is "/etc/php5/cli/php.ini", then add/modify the include_path = ".:/usr/share/php" – zhihong Oct 10 '13 at 13:36
4

After 2 days of post reading, finally i've solved with guides:

Clean pc by hold/corrupted installation of Phpunit LINK

and reinstalled with this guide LINK

Community
  • 1
  • 1
Teo
  • 41
  • 1
3

For me the fix was simple (Ubuntu 12.04). First I did a search to make sure the file existed and where it was located:

locate Autoload.php

Which should return results similar to this:

/usr/share/php/File/Iterator/Autoload.php
/usr/share/php/PHP/CodeCoverage/Autoload.php
/usr/share/php/PHP/Depend/Autoload.php
/usr/share/php/PHP/Invoker/Autoload.php
/usr/share/php/PHP/Timer/Autoload.php
/usr/share/php/PHP/Token/Stream/Autoload.php
/usr/share/php/PHPCPD/Autoload.php
/usr/share/php/PHPUnit/Autoload.php
/usr/share/php/PHPUnit/Framework/MockObject/Autoload.php
/usr/share/php/PHP_CodeBrowser/Autoload.php
/usr/share/php/Text/Template/Autoload.php

Then I checked my include_path, which was set correctly in /etc/php5/apache2/php.ini, but was still commented out in /etc/php5/cli/php.ini (the command line interface).

Uncommenting this line worked for me:

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

Pretty basic I know, but it's always the little things when setting up a new machine ;-)

jreuter
  • 31
  • 3
3

All kind of nice things I have read on this one. First check where the Autoload.php is located. Use:

$ find . -name 'Autoload.php' -type f

I assume that your files are located in:

/usr/local/pear/share/pear


I have Apple OSX 10.8.4 MAMP and MAMP-PRO installed and I have several other PHP installations.
For the last one I have done the following: First check if there is a php.ini in the directory: /private/etc
If not, do:

$ sudo cp /private/etc/php.ini.default /private/etc/php.ini

Add the following lines at the bottom of the 'php.ini' file:

; *** Added by <your-name> ****
include_path=".:/usr/local/pear/share/pear"
; *** Ended addition ****

Done.

Harm
  • 787
  • 7
  • 11
2

I had the same problem using PhP 5.3 on OSX 10.6 using the built-in server configuration.

I noticed that while PHPUnit was being successfully installed to /usr/lib/php, Autoload.php was trying (line 45) to load the File Iterator from its current directory (/usr/lib/php/PHPUnit) rather than the directory Pear was installing it to (/usr/lib/php/File). Could this be a bug in the Pear installer?

A simple ln -s /usr/lib/php/File /usr/lib/php/PHPUnit/File solved the problem.

DMCoding
  • 1,167
  • 2
  • 15
  • 30
  • This is a kludge. The real reason is a misconfigured include_path in php.ini . This just masks the real problem, and can break again easily if things change slightly. – Tim Seguine Sep 10 '13 at 09:45
  • 1
    @Tim, thanks for the explanation, I had this question at first place and almost try to change the "require_once" path. And later figure it out by modify the php.ini. – zhihong Oct 10 '13 at 13:40
1

I am using Ubuntu 14.04 and I installed phpunit via Ubuntu Software Center which didn't work.

Finally I remove it and I followed instructions from here

wget https://phar.phpunit.de/phpunit.phar  
chmod +x phpunit.phar  
sudo mv phpunit.phar /usr/local/bin/phpunit
Faishal
  • 1,493
  • 1
  • 14
  • 23
Stilgar
  • 124
  • 1
  • 8
0

Also, using open-server bundle one can notice that it reports way too short include_path.

To fix this on Windows 7 you can do

cd c:\Windows
mklink php.ini c:\OpenServer\userdata\temp\config\php.ini
Ilya Sheershoff
  • 409
  • 4
  • 10
0

I had the same issue with windows 7 and xampp(php 5.6.11), I tried all reinstalling pear and phpunit but it didn't work. When I checked the permission of the C:\xammp\php\pear directory it was read-only, After I changed the permission it started working.

0

Look at the error:

 (include_path='.;C:\php\pear') in C:\xampp\php\pear\PHPUnit\Autoload.php

The Xampp is trying to locate that file in include_path .;C:\php\pear But The path for the pear is .;C:\xampp\php\pear.

Set the right path for the pear and it will work. I just made it.

Leap Hawk
  • 622
  • 1
  • 6
  • 25