include_path when using PHPUnit

Hi,

I tried to write some code using PHPUnit. It seems the test runner does not pass the project path to the include_path, and so there is not any way I could access my production code from the tests. How this really should be used? All the examples on your web page seems to be testing some simple internal PHP functions, not actual production code.

For example:
If my test code contains require_once to load the production code to be tested:


require_once 'includes/db_utils.php';


The test execution fails with error:

E_COMPILE_ERROR: require_once(): Failed opening required 'includes/db_utils.php' (include_path='.:/usr/lib/php')


The current path when executing the test runner seems to be "/Applications/PhpStorm-95.74.app/bin", not for example my project root. If the php process would be run on the project root, or the include_path would be set accordingly, everything would be just fine.

Cheers,
Janne
0
2 comments

Hello! Yes that's the bootle neck. Which directory should be made current is not obvious. But, what I think would be right solution is to make 'Custom working directory' field in run configuration dialog. Will it solve your problem?
--
Thanks

0

Note that PhpStorm will never modify your actual php.ini include_path (in most typical setups with remote server its not even possible)

The working directory option (with appropriate default to script location) will be added in next EAP - this will make "." include_path and relative paths in include directives work.

0

Please sign in to leave a comment.