PHPunit - CLI PHP file includes/requires
For example if I have a php script called "RunAllTests.php" in '/var/www/tests/RunAllTests.php' and I execute phpunit within the that directory, the includes in "RunAllTests.php" are found.
If I execute phpunit on that same file, from another directory, lets say '/var开发者_如何学JAVA/www/', the included files in "RunAllTests.php" cannot be located. - "failed to open stream: No such file or directory in"
I kept this a little bit vague, let me know if you need some more specifics.
Your requires are wrong / not portable: they expect the directory of the file (or some other fixed directory) to be the working dir.
Your options are:
- Just start the process from the correct dir.
chdir(__DIR__)
in your script.- include / require relative to the
__DIR__
constant in your files (which IMHO is most portable) - define a working dir in code beforehand, use that value (related to (3) but more fixed).
精彩评论