I’m setting up unit testing for the first time on my Zend Framework app (and it’s actually the first time I’m doing unit testing at all).
A problem I’m getting at the moment is that I use a view helper to include my headscripts and links:
class Zend_View_Helper_HeadIncludes extends Zend_View_Helper_Abstract {
public function headIncludes($type, $folder) {
if($folder == "full" && APPLICATION_ENV == "production") {
$folder = "min";
}
$handler = opendir(getenv("DOCUMENT_ROOT") . "/". $type ."/" . $folder);
while ($file = readdir($handler)) {
if ($file != "." && $file != "..") {
if($type == "js") {
$this->view->headScript()->appendFile('/js/' . $folder . '/' . $file);
} else if ($type == "css" ) {
$this->view->headLink()->appendStylesheet('/css/' . $folder . '/' . $file);
}
}
}
closedir($handler);
}
}
This is included in each view script. When I try and run a test it fails because opendir() tries to find eg “/css/full” relative to the document root, which seems to not be the same value for tests and the application. What’s the best way to resolve this? I could add in a conditional to do something different when APPLICATION_ENV = “testing”, but am not sure if this would run contrary to what setting up testing is supposed to achieve.
The environment variable ‘DOCUMENT_ROOT’ is only going to be set by your web server. You may want to be using ‘APPLICATION_PATH’ as a reference instead as it’s more reliable across virtual hosts as well as command line usage.