问题
I have installed PHPUnit
and checked my PEAR
settings and everything went fine. I'm using Yii
as my framework and I am on a linux shared server. When I run a test (any test) I get the errors below. From what I can tell I think I need to add the following to my path settings:
/home/myname/php/
since that is where both the PHP and PHPUnit
folders are located. I am unable to modify the php.ini file since I am on a shared server. I am wondering if this is really the problem and if anyone else has found and fixed this issue in a shared environment?
/protected/tests/unit]# phpunit dbTest.php
X-Powered-By: PHP/5.2.9
Content-type: text/html
<br />
<b>Warning</b>: require_once(PHPUnit/Util/Filter.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream: No such file or directory in /home/myname/bin/phpunit on line 40<br />
<br />
<b>Fatal error</b>: require_once() [<a href='function.require'>function.require</a>]: Failed opening required 'PHPUnit/Util/Filter.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/myname/bin/phpunit on line 40
回答1:
After much trial and tribulation I figured it out. Hope this helps someone else.
Since I am on a shared server I cannot adjust the include_path. It won't work using a .htaccess file either because phpunit is run from the command line and doesn't invoke the .htaccess file. Therefore, setting an include path in a .htaccess is fruitless if you're having the same problems as I was with phpunit.
The only path that I am now able to get phpunit tests to run from is /home/myname/php. That is because my PHPUnit files automatically install in /home/myname/php/PHPUnit.
When running a phpunit test from /home/myname/php I would get an error stating
File "/home/... " could not be found
At this point I found that I needed to upgrade PHPUnit, which in turn upgraded a number of its dependencies (CodeCoverage, Selenium and others). The command to upgrade phpunit was
pear upgrade phpunit/PHPUnit
Now I can successfully run tests from the /home/myname/php folder and it works. If I run the tests from any other folder it fails because it is searching the include_path directories and /home/myname/php is not one of those paths.
回答2:
check that your PHPUnit exists in /usr/lib/php/PHPUnit, ortherwise, you have to include your path for your PHPUnit in your PHP.ini.
check your Loaded Configuration File (PHP.ini) you are using with
php --ini
put a PEAR directory in "include_path" line.
回答3:
Joe, try to add /home/myname/php/ to your path like:
export PATH=/home/myname/php/:$PATH
Also, look at http://php.net/set_include_path
来源:https://stackoverflow.com/questions/4171528/phpunit-and-yii-on-a-shared-server