-- Andrew Havens <[email protected]> wrote
(on Tuesday, 17 March 2009, 01:40 PM -0700):
> I know there are a few tutorials floating around the web, but I'm
> still a little confused. I already have PHPUnit installed and working.
> Now I'm trying to write a simple controller test using Zend_Test.
>
> Assuming my application is exactly the same as the
> http://framework.zend.com/docs/quickstart tutorial, and going through
> http://framework.zend.com/manual/en/zend.test.phpunit.html ... can you
> please explain how I autoload Zend_Test_PHPUnit_ControllerTestCase?
> The documentation assumes that "autoloading is setup so we do not need
> to worry about requiring the appropriate classes (such as the correct
> controller, plugin, etc)." But that is the part I am confused about.
>
> In the quickstart tutorial, we put Zend_Loader::registerAutoload(); in
> our index.php file, but our tests don't run through index.php. So does
> that mean in my tests, I will need to put all the include path,
> autoload information in the test, like I did in index.php? What should
> I do? What would be the best scenario for requiring/including the
> necessary files that my test class will extend?
I usually create a TestHelper.php file that I include in every test
case, and this file sets up things such as the include_path, autoloader,
error reporting settings, etc. As an example:
<?php
// TestHelper.php
ini_set('display_errors', true);
error_reporting( E_ALL | E_STRICT );
ini_set('memory_limit', -1);
date_default_timezone_set('GMT');
defined('APPLICATION_PATH')
or define('APPLICATION_PATH', realpath(dirname(__FILE__) .
'/../application'));
defined('APPLICATION_ENV')
or define('APPLICATION_ENV', 'testing');
set_include_path(/* something reasonable */);
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
Then, in the individual test class files, I require it:
<?php
// modify path as necessary...
require_once dirname(__FILE__) . '/../TestHelper.php';
class FooControllerTest extends Zend_Test_PHPUnit_ControllerTestCase
{
// ...
}
--
Matthew Weier O'Phinney
Software Architect | [email protected]
Zend Framework | http://framework.zend.com/