Using phpunit and I am having some trouble with include paths, not for phpunit itself, but for my code and tests directory.
I have the following code structure:
Application
-StringCalculator.php
tests
-StringCalculatorTest.php
Inside my StringCalculatorTest.php i have a require statement:
require_once('../StringCalculator.php');
Running phpunit StringCalculatorTest.php
from inside the tests folder works perfectly.
However, when i then introduce a phpunit.xml configuration file in the root directory i.e.
Application
-StringCalculator.php
tests
-StringCalculatorTest.php
phpunit.xml
the include path is screwed. I have to replace the require_once to
require_once('StringCalculator.php');
What is the correct way to set include paths between the application and the test directory?
The best place to set your PHP include path is in your bootstrap file. Usually, your
phpunit.xml
file will include a bootstrap attribute:Then in your bootstrap file you can set include paths, include important files, etc..
The config file is covered in Appendix C of the PHPunit docs.
EDIT: Link updated