0

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/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.

1 Answer 1

2

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:

  1. Just start the process from the correct dir.
  2. chdir(__DIR__) in your script.
  3. include / require relative to the __DIR__ constant in your files (which IMHO is most portable)
  4. define a working dir in code beforehand, use that value (related to (3) but more fixed).
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks wrikken. Ended up using chdir since some of the includes are relative paths 1 directory back which was making the magicvar DIR not applicable I believe... still learning.
Well, you can still include __DIR__.'/../levelhigherfile.php';
You can put the value of __DIR__ in a constant APPLICATION_PATH or TEST_PATH and use that constant in your other files.
...which is what I meant with point (4), sorry if that wasn't clear.

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.