(on Wednesday, 28 January 2009, 12:33 AM -0800):
> After not receiving any answers I think, my Mail have been lost in some big
> big e-mail accounts.
> So I send it again. My problem is, that my application is giving me the
> message "Zend_Controller_Exception: No default module defined for this
> application" but I don't get why :/
>
> Here are the listings again:
<snip>
> --------------------
> TestHelper.php
> --------------------
<snip>
> /**
> * Store application root in registry
> */
> Zend_Registry::set('testRoot', $root);
> Zend_Registry::set('testBootstrap', $root . '/src/index.php');
I'm assuming that the test bootstrap is different than the one used for
the site. Is this correct?
> // get the front controller
> $front = Zend_Controller_Front::getInstance();
>
> // set up this app as modular one
> $front->addModuleDirectory(dirname(__FILE__) . '/intranet/modules');
> $front->setDefaultModule('dashboard');
> $front->setControllerDirectory(
> array(
> 'default' => dirname(__FILE__) .
> '/intranet/modules/dashboard/controllers',
> 'dashboard' => dirname(__FILE__) .
> '/intranet/modules/dashboard/controllers',
> 'pppservice' => dirname(__FILE__) .
> '/intranet/modules/pppservice/controllers'
> )
> );
One note with the above: you've got some duplication of logic. All of
the controller directories you add using setControllerDirectory() should
have already been added with the addModuleDirectory() statement.
<snip>
> --------------------
> index.php
> --------------------
I'm a little unclear -- is this src/index.php, or public/index.php? Some
of the settings below are ones that have either been done in the
TestHelper.php above, or are inappropriate for a non-HTTP environment.
Could you clarify?
<snip>
> // error_reporting( E_ERROR | E_WARNING | E_PARSE | E_NOTICE );
I typically set error_reporting in my testing environment to 'E_ALL |
E_STRICT', as this will report all errors.
> header('content-type: text/html; charset=UTF-8');
Also, in your test bootstraps, you shouldn't call header(), as header()
issues a notice in the PHPUnit environment. I'd typically recommend that
a header such as the above be injected into your response object
instead, which will make the application more testable as well. You
could do so either in a plugin, or in the bootstrap (and just make sure
you inject the response object into the front controller prior to
dispatching).
> set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) .
> '/library');
>
> require_once 'Zend/Loader.php';
> Zend_Loader::registerAutoload();
The above statements would not be necessary if this is the bootstrap for
your testing, as they're already covered in TestHelper.php...
> // start session
> Zend_Session::start();
>
> // get the front controller
> $front = Zend_Controller_Front::getInstance();
>
> // set up this app as modular one
> $front->addModuleDirectory(dirname(__FILE__) . '/intranet/modules');
>
> // FOR DEVELOPMENT ONLY
> $front->throwExceptions(true);
>
> // start Zend_Layout
> Zend_Layout::startMvc(
> array(
> 'layout' => 'default'
> , 'layoutPath' => dirname(__FILE__) . '/intranet/layout/scripts'
> )
> );
>
> // fill the registry with some useful data
> Zend_Registry::set('mandants', new Zend_Config_Ini(dirname(__FILE__) .
> '/intranet/config/application.ini', 'mandants'));
>
> Zend_Registry::set(
> 'dbh-maindb',
> Zend_Db::factory(
> new Zend_Config_Ini(dirname(__FILE__) .
> '/intranet/config/application.ini',
> 'maindb-dev')
> )
> );
>
> Zend_Registry::set(
> 'dbh-staffdb',
> Zend_Db::factory(
> new Zend_Config_Ini(dirname(__FILE__) .
> '/intranet/config/application.ini',
> 'staffdb-dev')
> )
> );
>
> Zend_Registry::set('basePath', dirname($_SERVER['PHP_SELF']));
>
>
> // pre-configure the table data gateway
> Zend_Db_Table_Abstract::setDefaultAdapter('dbh-maindb');
>
> $http = new Zend_Http_Client();
>
> // configure router
> $front->getRouter()->addRoute(
> 'default',
> new Zend_Controller_Router_Route(':module/:controller/:action/*',
> array(
> 'module' => 'dashboard'
> , 'controller' => 'index'
> , 'action' => 'index'
> )
> )
> );
>
> // now dispatch
> try {
>
> $front->dispatch();
Also, in your test bootstrap, you wouldn't dispatch the front
controller... so I'm guessing this is your public bootstrap?
> } catch(Exception $e) {
>
> throw $e;
> // THIS IS ONLY FOR DEVELOPMENT USE!
> // echo nl2br( $e->__toString() );
>
> }
>
>
> --------------------
> WeekplannerControllerTest.php
> --------------------
>
> <?php
>
> require_once 'TestHelper.php';
>
> class PPPService_WeekplannerControllerTest extends
> Zend_Test_PHPUnit_ControllerTestCase {
>
> /*
> * Sets up the bootstrap.
> * This method is called before a test is executed.
> *
> * @return void
> */
> public function setUp()
> {
> $this->view = new Zend_View_Helper_Placeholder();
> $this->bootstrap = Zend_Registry::get('testBootstrap');
> return parent::setUp();
> }
>
> /**
> * Tests setting title of page
> * Needs assertion!!!!
> */
>
> public function testSetTitle()
> {
> $this->view->placeholder('layoutTitle')->set("phpUnit Test Title for
> PPPService");
> $this->dispatch('pppservice/weekplanner');
dispatch() expects a URI -- prepend it with a slash:
$this->dispatch('/pppservice/weekplanner');
and that may make a difference here.
> }
>
> public function testCurrentAction()
> {
> $this->dispatch('pppservice/weekplanner/current');
Same advice here.
> }
> }
--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/
没有评论:
发表评论