Has anyone had any success setting up Zend_Test? What was your method/approach and how do you run your tests/test suites?
I already have PHPUnit installed and working. Now I'm trying to write some simple controller tests. The Zend Framework documentation assumes that autoloading is setup, which I haven't done. What method do you use to autoload the appropriate files? I do so in my normal bootstrap file, but I don't want to clutter up my Test with a bunch of includes and setting up paths. Would an abstract controller test case class be the way to go?
What about the bootstrap plugin like the documentation uses...is that how you bootstrap your tests, or do you like to do it a different way? I would like to re-use as much of the regular bootstrap file as I can. How should I DRY up my bootstrap for testing and normal use?
Here's my test so far:
<?php
class IndexControllerTest extends Zend_Test_PHPUnit_ControllerTestCase
{
public function setUp()
{
$this->bootstrap = array($this, 'appBootstrap');
parent::setUp();
}
public function appBootstrap()
{
$this->frontController->registerPlugin(new Bootstrapper('testing'));
}
public function testIndexAction()
{
$this->dispatch('/index');
$this->assertController('index');
$this->assertAction('index');
}
}
//straight from the documentation
class Bootstrapper extends Zend_Controller_Plugin_Abstract
{
/**
* @var Zend_Config
*/
protected static $_config;
/**
* @var string Current environment
*/
protected $_env;
/**
* @var Zend_Controller_Front
*/
protected $_front;
/**
* @var string Path to application root
*/
protected $_root;
/**
* Constructor
*
* Initialize environment, root path, and configuration.
*
* @param string $env
* @param string|null $root
* @return void
*/
public function __construct($env, $root = null)
{
$this->_setEnv($env);
if (null === $root) {
$root = realpath(dirname(__FILE__) . '/../../../');
}
$this->_root = $root;
$this->initPhpConfig();
$this->_front = Zend_Controller_Front::getInstance();
}
/**
* Route startup
*
* @return void
*/
public function routeStartup(Zend_Controller_Request_Abstract $request)
{
$this->initDb();
$this->initHelpers();
$this->initView();
$this->initPlugins();
$this->initRoutes();
$this->initControllers();
}
// definition of methods would follow...
}
What should I do?