views:

28

answers:

1

I'm still a newb to phpunit so I hope to be explaining this correctly. I'm trying to run a controller test with PHPUnit, however the plugin that is using Zend_Auth is redirecting back to the login. How do I create the stub data? I tried placing it in my setUp but Zend_Auth appears to be reinstantiated after setUp. Thanks for any help

A: 

You just have to authenticate in your testcase manually. Say, if you have a custom class My_Auth_Adapter which implements Zend_Auth_Adapter_Interface, you can do something like this:

// authentication - you can place it in setUp() method if you want
$adapter = new My_Auth_Adapter('someusername', 'somepassword');
Zend_Auth::getInstance()->authenticate($adapter);

// checking if it's successful
$this->assertTrue(Zend_Auth::getInstance()->hasIdentity());

// testing your controller code
$this->dispatch('/some/url');
$this->assertController('some');
$this->assertAction('url');
$this->assertXpath(/*some element on your page*/);
// and so on
Wallgate