3

Having a lot of problems installing phpunit with Yii. I run:

$ phpunit unit/dbTest.php

But it turns out this error:

PHP Warning: require_once(PHPUnit/Autoload.php): failed to open stream: No such file or directory in /opt/yii-1.1.10.r3566/framework/test/CTestCase.php on line 12

(include_path='.:/usr/bin:/usr/share/php:/usr/bin/pear:/usr/share/php/Zend/:/opt/php5.3.10/lib/php/PHPUnit'

Some details about my installation:

$ phpunit --version
PHPUnit 3.4.5 by Sebastian Bergmann.

php --version
PHP 5.3.10 (cli) (built: Apr  6 2012 20:06:37) ( rebuilt didn't help :( )

pear list phpunit/phpunit
....
php    /opt/php5.3.10/lib/php/PHPUnit/Autoload.php

According to that info, autoload is installed, and is on the include path.

I'm unsure what else I need to do - can anyone shed a light please?

2
  • How did you install PHPUnit? Those commands are missing, so it's hard to tell where exactly your error lies, however, the include path is wrong, that's why it can not require the file (as the error message tells you as well. it's not lying). Commented Jun 15, 2012 at 10:20
  • your error is a result of the file looking for PHPUnit/Autoload.php your include path does not have PHPUnit/Autoload.php as a result of setting the PHPUnit directory of include without the parent directory. Commented Sep 2, 2012 at 18:49

2 Answers 2

3

I hope this is of some use to someone:

It seems on ubuntu PEAR is broken for this task and apt-get won't help either.

This is how i solved it

Manually download from http://pear.phpunit.de/

phpunit/PHPUnit

and

phpunit/File_Iterator
PHPUnit_MockObject
phpunit/PHPUnit_Selenium
PHP_CodeCoverage

Manually dezip and put correctly in php lib or wherever you want them to go. Put the head of this library on your include path (PHP, PHPlib, PEAR are all at this root level on my setup.)

Goddam, hope that helps someone i spent about 6 hours getting this to work last nite...

Sign up to request clarification or add additional context in comments.

1 Comment

Actually you run a bit like crazy here. It might be that there was in issue when you used the pear installer. Always upgrade pear first. Then check the include path, it would have revealed that it was not correct (not it was not in the include path, you only thought so). In debugging: Before running crazy, step back and proof what the exact cause is first. Then fixing is easy, e.g. configuring the include path properly.
2

As rix shows in his answer, you have to download some files manually.

I got it working on Ubuntu 10.04 following these commands:

wget http://pear.phpunit.de/get/PHPUnit-3.6.10.tgz
wget http://pear.phpunit.de/get/File_Iterator-1.3.1.tgz
wget http://pear.phpunit.de/get/PHPUnit_MockObject-1.1.1.tgz
wget http://pear.phpunit.de/get/PHPUnit_Selenium-1.2.6.tgz
wget http://pear.phpunit.de/get/PHP_CodeCoverage-1.1.2.tgz
wget http://pear.phpunit.de/get/PHP_TokenStream-1.1.3.tgz
wget http://pear.phpunit.de/get/Text_Template-1.1.1.tgz
wget http://pear.phpunit.de/get/PHP_Timer-1.0.2.tgz

sudo vi /etc/php5/cli/php.ini

=> add /usr/share/php/PHPUnit/ to include_path directive

tar xzf PHPUnit-3.6.10.tgz 
cd PHPUnit-3.6.10/
sudo cp -r PHPUnit/ /usr/share/php/
sudo ln -s /usr/share/php/PHPUnit /usr/bin/PHPUnit

tar xzf File_Iterator-1.3.1.tgz
sudo cp -r File/ /usr/share/php/PHPUnit/

tar xzf PHP_CodeCoverage-1.1.2.tgz
cd PHP_CodeCoverage-1.1.2/
sudo cp -R PHP/ /usr/share/php/PHPUnit/

tar xzf PHP_TokenStream-1.1.3.tgz
cd PHP_TokenStream-1.1.3/PHP/
sudo cp -r Token* /usr/share/php/PHPUnit/PHP/

tar xzf Text_Template-1.1.1.tgz
cd Text_Template-1.1.1/
sudo cp -r Text/ /usr/share/php/PHPUnit/

tar xzf PHP_Timer-1.0.2.tgz 
cd PHP_Timer-1.0.2/
sudo cp -r PHP/Timer* /usr/share/php/PHPUnit/PHP/

tar xzf PHPUnit_MockObject-1.1.1.tgz
cd PHPUnit_MockObject-1.1.1/
sudo cp -r PHPUnit/Framework/MockObject/ /usr/share/php/PHPUnit/Framework/

tar xzf PHPUnit_Selenium-1.2.6.tgz
cd PHPUnit_Selenium-1.2.6/
sudo cp -r PHPUnit/Extensions/* /usr/share/php/PHPUnit/Extensions/

2 Comments

I added add /usr/share/php/ to include_path instead of add /usr/share/php/PHPUnit/ and it worked. Thank you.
On Ubuntu I was able to install it using this: sudo pear install --force --alldeps pear.phpunit.de/PHPUnit (you have to discover the pear.phpunit.de channel but i think that's it)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.