PHPUnit and Working Directories
I'm using the PHPUnit framework for unit testing some code I'm writing for a couple of websites. To avoid figuring out the seemingly convoluted API for building a suite of tests, I had to rearrange my directory structure. All of my test classes are in a Tests directory that is a child of the directory where the working code is located. I also had to split out each test class into its own separate file (similar to Java).
In moving the tests to a subdirectory, I had to change my
It turns out that
There are two solutions:
I chose option 2.
In moving the tests to a subdirectory, I had to change my
require_once
statements to point to the parent directory via a relative path. At least, I thought I did.It turns out that
require_once
operates on the current working directory. I was using the following command:C:\Source\> phpunit TestsThe current working directory was C:\Source, so when the require_once attempted to resolve the path, it was looking in C:\.
There are two solutions:
- Remove the relative path markers
- Run phpunit from within the Tests directory
I chose option 2.