Question

i have problem with testing zend_session, my test look like that:

Bootstrap.php

public function _initSession() {
    try
    {
        Zend_Session::setSaveHandler(new APP_Session_SaveHandler_Memcached());            
        Zend_Session::start();

        $session = new Zend_Session_Namespace('APP');
        Zend_Registry::set('session', $session);
    }
    catch(Exception $e) 
    {
        Zend_Registry::get('log')->err($e);
    }
}  

SessionTest.php

public function testSession() { 
    $session = Zend_Registry::get('session');
    $session->setExpirationSeconds(1);
    $session->testIndex = "testValue";

    $this->assertEquals('testValue', $session->testIndex);

    sleep(3);

    $this->assertEquals(null, $session->testIndex);
}

first assertion is ok, but the second always say that value of $session->testIndex is "testValue", when it should be null right?

If i'am wrong, please tell me, because I can't figure it out.

Was it helpful?

Solution

The expiry time isn't evaluated every time you access data from the session class, just when it is first loaded. A typical PHP script should never take over a second to execute, so the case you are trying to test shouldn't ever happen in a real world situation.

I'd also add that there's not a lot of point testing functionality that exists in ZF like this - the ZF classes are already unit tested. Test your application, not the framework.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top