0
votes

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
try to catch the exception inside the test - opHASnoNAME
I'm still newbie in unit testing and eager to learn it. I'll try to find out about how to use exception in unit testing. Thank you. - deerawan
@bhoo-day, getAll() or fetchAll()? - allnightgrocery
oh sorry, forget to mention it..getAll() is my custom method that call fetchAll() :) - deerawan
I got a clue that if I create pure model (not extend Zend_Db_Table_Abstract), unit testing is success. - deerawan

1 Answers

0
votes

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. :)