PHPUnit include statements not working properly

Hello everyone,


I am using Travis.CI to run my unit tests and am running into problems where the include filepath statements can’t be found. The unit tests are found and ran, but the file with my functions that I want to test is not found, so it fails all the tests. When have run all the unit tests locally on the PHPStorm IDE, as well as created other test files with similar file paths and they work just fine. I am sure that I’m missing something here because I am new to travis and also to unit testing.


Here is the link to my build https://travis-ci.org/WSU-4110/humdrum


And here is the link to my github repo and specifically to the test file that is failing https://github.com/WSU-4110/humdrum/blob/master/tests/firstTest.php


Help is appreciated

1 Like

Same problem… Test runs fine locally, but when it runs on the virtual server I get

include(…/…/…/path/to/thing.php): failed to open stream: No such file or directory

This is hard to say what exactly is going on with such little information.

However in both reports the paths of the files to include are relative. The screenshot additionally shows that the include path contains no directory that could successfully include from.

Paths in PHP to include can be relative but most often are relative to __DIR__ which is the (absolute) path of the file __DIR__ is written into (please see PHP manual for details on these so called “magic constants”).

E.g. the following could already work:

include(__DIR__ . '/../../../path/to/thing.php'):
        ^^^^^^^^^^^^

Just prefix the relative (now to the file itself) path with __DIR__ , . and a directory separator (/).