Problem solved thanks to you! So I added that first line as requested to both
testcases:

   public function testCallWithoutActionShouldPullFromIndexAction()
    {
       
$this->fail(var_export($this->frontController->getControllerDirectory(),
1)); 
        $this->dispatch('/');
        $this->assertResponseCode(200);
        $this->assertAction('index');
        $this->assertController('index');
    }

    public function testValidLoginShouldGoToIndexPage()
    {
       
$this->fail(var_export($this->frontController->getControllerDirectory(),
1));        
        $this->request->setMethod('POST')
              ->setPost(array(
                  'user_name' => TESTS_LOGIN_NAME,
                  'user_password' => TESTS_LOGIN_PASSWORD
              ));
        $this->dispatch('/GoGoVerde/www/user/login/');
        $this->assertResponseCode(200);
        $this->assertAction('index');
        $this->assertController('index');
    }

with this result:

There were 2 failures:

1) testCallWithoutActionShouldPullFromIndexAction(Ggv_LoginTest)
array (
  'default' => '/Library/WebServer/Documents/GGV/application/controllers',
)

2) testValidLoginShouldGoToIndexPage(Ggv_LoginTest)
array (
)

for the second test case the controller directory was not defined as you
said. What had happened was 
that most of my index.php is in a try catch:
try
{
    $configEnv = new Zend_Config_Ini(GGV_PATH_ROOT . '/config/main.ini',
'bootstrap');
    $config = new Zend_Config_Ini(GGV_PATH_ROOT . '/config/main.ini',
$configEnv->env);
    Zend_Registry::set('config', $config);
    defined('GGV_SCHEMA') or define('GGV_SCHEMA', $config->db->schema);
    $db = Zend_Db::factory($config->db);
    Zend_Db_Table_Abstract::setDefaultAdapter($db);
    Zend_Registry::set('db', $db);
    $configSession = new Zend_Config_Ini(GGV_PATH_ROOT .
'/config/session.ini', $configEnv->env);
    Zend_Session::setOptions($configSession->toArray());
    Zend_Session::start();
    $session = new Zend_Session_Namespace('GoGoVerde');
    Zend_Session::regenerateId();
    if ($session->user_authenticated)
    {
        $session->setExpirationSeconds($config->session->expire);
    }
    Zend_Registry::set('session', $session);
    $front = Zend_Controller_Front::getInstance();
    $front->registerPlugin(new LoggerPlugin());
    $front->throwExceptions(false);
    $front->setControllerDirectory(GGV_PATH_ROOT .
'/application/controllers');
    $front->setBaseUrl($config->www->baseurl);
    if (GGV_DISPATCH_FRONT_CONTROLLER)
    {
       $front->dispatch();
    }
}

to bring up an "under maintenance" page e.g. when the database is down and
an exception is thrown. The problem was that when the bootstrap ran for the
second test case the define('GGV_SCHEMA') had not been wrapped in a defined
or so it threw an exception. Once I changed that the testcase ran fine.

Thanks!!
Peter


Matthew Weier O'Phinney-3 wrote:
> 
> -- Peter Wansch <[EMAIL PROTECTED]> wrote
> (on Sunday, 31 August 2008, 10:17 PM -0700):
>> 
>> Hi Matt,
>> Thanks for the explanation. I ensured that GGV_DISPATCH_CONTROLLER is set
>> to
>> false:
>> 
>>     public function setUp()
>>     {
>>         // Execute any startup code here
>>         defined('GOGOVERDE_DISPATCH_FRONT_CONTROLLER') or
>> define('GOGOVERDE_DISPATCH_FRONT_CONTROLLER', false);
>>         parent::setUp();
>>     }
>> 
>> right where you suggested I should define it. I still get the same error.
>> Here is the output from phpunit:
>> 
>> 1) testValidLoginShouldGoToIndexPage(Ggv_LoginTest)
>> Zend_Controller_Exception: No default module defined for this application
>> /Library/WebServer/ZendFramework-1.6.0RC3/library/Zend/Controller/Dispatcher/Standard.php:211
>> /Library/WebServer/ZendFramework-1.6.0RC3/library/Zend/Controller/Dispatcher/Standard.php:245
>> /Library/WebServer/ZendFramework-1.6.0RC3/library/Zend/Controller/Front.php:946
>> /Library/WebServer/ZendFramework-1.6.0RC3/library/Zend/Test/PHPUnit/ControllerTestCase.php:172
>> 
>> Any ideas what the reason for that could be?
> 
> Is GGV_PATH_ROOT defined? I noticed that you're setting the controller
> directory based on that information.
> 
> Also, can you do this as the first action in your test:
> 
>    
> $this->fail(var_export($this->frontController->getControllerDirectory(),
> 1));
> 
> This will let you know if the front controller has set controller
> directories for you prior to dispatching. 
> 
> 
>> Matthew Weier O'Phinney-3 wrote:
>> > 
>> > -- Peter Wansch <[EMAIL PROTECTED]> wrote
>> > (on Sunday, 31 August 2008, 04:19 PM -0700):
>> >> I wrote the following unit test case:
>> >> 
>> >> class Ggv_LoginTest extends Zend_Test_PHPUnit_ControllerTestCase
>> >> {
>> >>     public $bootstrap =
>> '/Library/WebServer/Documents/GGV/www/index.php';
>> >> 
>> >>     public function testCallWithoutActionShouldPullFromIndexAction()
>> >>     {
>> >>         $this->dispatch('/');
>> >>         $this->assertResponseCode(200);
>> >>     }
>> >> 
>> >>     public function testValidLoginShouldGoToIndexPage()
>> >>     {
>> >>         $this->request->setMethod('POST')
>> >>               ->setPost(array(
>> >>                   'user_name' => TESTS_LOGIN_NAME,
>> >>                   'user_password' => TESTS_LOGIN_PASSWORD
>> >>               ));
>> >>         $this->dispatch('/GGV/www/user/login/');
>> >>         $this->assertResponseCode(200);
>> >>     }
>> >> }
>> >> 
>> >> The first test case that dispatches to '/' works. The second test case
>> >> that
>> >> dispatches to throws Zend_Controller_Exception: No default module
>> defined
>> >> for this application. I use the same index.php bootstrap file for
>> running
>> >> the application and testing the application. Here is a relevant
>> excerpt:
>> >> 
>> >> defined('GGV_DISPATCH_FRONT_CONTROLLER') or
>> >> define('GGV_DISPATCH_FRONT_CONTROLLER', true);
>> >> 
>> >>     // Set the session into the registry
>> >>     Zend_Registry::set('session', $session);
>> >> 
>> >>     // Set up the front controller and dispatch
>> >>     $front = Zend_Controller_Front::getInstance();
>> >>     $front->registerPlugin(new LoggerPlugin());
>> >>     $front->throwExceptions(false);
>> >>     $front->setControllerDirectory(GGV_PATH_ROOT .
>> >> '/application/controllers');
>> >>     $front->setBaseUrl($config->www->baseurl);
>> >>     if (GGV_DISPATCH_FRONT_CONTROLLER)
>> >>     {
>> >>         $front->dispatch();
>> >>     }
>> >> 
>> >> the only difference is that in my test case I require_once a test
>> >> configuration PHP file that defines GGV_DISPATCH_FRONT_CONTROLLER to
>> >> false
>> >> as per the documentation the bootstrap file must not dispatch the
>> front
>> >> controller. Unlike all the samples given, I don't use a Bootstrap
>> class
>> >> or
>> >> callback in my testcase. It appears that Zend_Test does not use the
>> >> $front
>> >> controller I setup in my index.php but creates it's own which isn't
>> >> initialized and throws the error.
>> > 
>> > Well, Zend_Controller_Front is a singleton, so any instance of it is
>> > going to be the same instance, regardless of where it is executed.
>> > 
>> >> I have also experimented with adding a setUp
>> >> 
>> >> public function setUp()
>> >>     {
>> >>         // Execute any startup code here
>> > 
>> > I would define GGV_DISPATCH_FRONT_CONTROLLER right here, before calling
>> > parent::setUp() to ensure that you don't accidently dispatch the
>> > controller during bootstrapping.
>> > 
>> >>         parent::setUp();
>> >>     }
>> >> 
>> >> method into my testcase and trying to set the
>> >> $this->frontController=$front
>> >> but the global variable that gets set in index.php is not available.
>> What
>> >> am
>> >> I doing wrong here? Any help is appreciated.
>> > 
>> > -- 
>> > Matthew Weier O'Phinney
>> > Software Architect       | [EMAIL PROTECTED]
>> > Zend Framework           | http://framework.zend.com/
>> > 
>> > 
>> 
>> -- 
>> View this message in context:
>> http://www.nabble.com/Zend_Test_PHPUnit_ControllerTestCase-with-bootstrap-php-file-tp19247111p19249003.html
>> Sent from the Zend Framework mailing list archive at Nabble.com.
>> 
> 
> -- 
> Matthew Weier O'Phinney
> Software Architect       | [EMAIL PROTECTED]
> Zend Framework           | http://framework.zend.com/
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Zend_Test_PHPUnit_ControllerTestCase-with-bootstrap-php-file-tp19247111p19256141.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to