TestCase BaseClass for Zend Framework
May 4, 2010 by Reboot · Leave a Comment
Just sharing some code here. If you’re planning to use the phpunit.xml then you would probably put all the setup logic in the bootstrap. I did a post before about setting up phpunit for Zend Server. Actually I configured the unit tests to run with the Zend Server executable in Zend Studio because it has a larger amount of extensions (Oracle connectivity to start with).
class TestCaseBase extends PHPUnit_Framework_TestCase
{
/**
* @var Zend_Application
*/
public $app;
public function setUp()
{
if (!defined('APPLICATION_PATH')){
define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application'));
}
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)
));
/** Zend_Application */
require_once APPLICATION_PATH . '/../library/Zend/Application.php';
$this->app = new Zend_Application('unittest',
realpath(APPLICATION_PATH . '/../tests/application/configs/application.ini'));
$this->app->setBootstrap(realpath(APPLICATION_PATH . '/../tests/application/bootstrap.php'));
$this->app->bootstrap();
$bs = $this->app->getBootstrap();
/* @var $front Zend_Controller_Front */
$front = $bs->getResource("FrontController");
$front->addModuleDirectory(realpath(APPLICATION_PATH . '/modules'));
$bs->registerPluginResource("modules");
$bs->bootstrap("modules");
}
public function tearDown()
{
/* Tear Down Routine */
}
public function log($message, $label = null)
{
if (null != $label) {
echo $label . ': ' . $message . "\n";
} else {
echo $message . "\n";
}
}
}