I am attempting to use Zend_Test_PHPUnit_ControllerTestCase in my testing and am experiencing difficulties.
My application bootstrap instantiates a library class that manages access to a Zend_Session_Namespace called 'LiveData'. LiveData maintains arrays of data for Current User, Current Organsation, etc. Once instantiated, the LiveData object is stored in the registry.
When I instantiate LiveData, I set singleInstance = true, ie. new Zend_Session_Namespace('LiveData', true) This is to reduce potential confusion about who does what to LiveData.
Anyhow, this seems to work fine. I browse the site, login, logout, etc, and my session data behaves as I would expect.
When trying to test, however, I get a message saying "A session namespace object already exists for this namespace".
My tests are bootstrapped in each test file as follows:
public function setUp()
{
$this->bootstrap = new Zend_Application(APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini');
parent::setUp();
}
This was the default scaffolding placed there by Netbeans. Reading the Zend_Test documentation, this seems fine to me.
The problem seems to arise when I dispatch a controller in a test, as follows:
public function testIndexIsDefaultAction()
{
$this->dispatch('/');
// assertions
$this->assertController('Index');
$this->assertAction('index');
}
I think that the test's setUp() method is resulting in my application bootstrap running (and creating a copy of LiveData). Then $this->dispatch('/') is running the bootsrap again... I can't imagine why this would be the case, though. (Why would we want it to run twice?) If you can shed any light on my plight, I'd be most appreciative!