Zend_Test: Assert Controller Failed

2019-06-13 01:31发布

问题:

I use Zend_Test for unit testing in Zend Framework. I have configured the bootstrap and testing environment properly then I got this error output from test unit

Failed asserting last controller used <"error"> was "index"

This error happens when I call my DbTable class inside action method such as

public function indexAction()
{
    $roleDb = new Model_DbTable_Role;
    $role = $roleDb->getAll();
    $this->_forward('login');
}

If I remove two lines role, unit testing is success. It is my unit testing code

public function testIndexActionShouldRedirectToLoginAction()
{
    $this->dispatch('/index');
    $this->assertController('index');
    $this->assertAction('login');
}

What's the problem with those lines?

How do I know the real error instead of just Failed asserting last controller used <"error">? Thank you

回答1:

Finally, it solved.

It was because of PDO pgsql was not detected by php unit. FYI, in XAMPP there are two files of php.ini.

First, inside apache/bin and second one is inside php folder. XAMPP always use the first php.ini for apache server but php unit use the second one. I have configured the first php.ini to use pgsql but forget the second one. It is the answer why my application still run but php unit doesn't.

Then, I enable extension for pgsql in the second php.ini

extension=php_pdo_mssql.dll
extension=php_pdo_mysql.dll
extension=php_pdo_pgsql.dll <= add it
;extension=php_pdo_oci.dll
;extension=php_pdo_oci8.dll
;extension=php_pdo_odbc.dll
extension=php_pdo_sqlite.dll
;extension=php_perl.dll
extension=php_pgsql.dll <= remove ';'

Last, thank you for any comments or suggestions for this problem. God bless you all. :)