Pergunta

I have ZF1 site and I'm testing it with phpunit.
I want to store cookies from one test(login) and pass it to other tests(post messages, etc).

Or is there any way to setIdentity?

This method doesn't work:

class IntegrationalTest extends ControllerTestCase {

    protected $identity;

    public function test1()
    {
        // some code here
        $this->assertTrue(Zend_Auth::getInstance()->hasIdentity()); // GOOD
        $this->identity = Zend_Auth::getInstance()->getIdentity();
    }

    public function test2() {
        Zend_Auth::getInstance()->getStorage()->write($this->identity);
        $this->assertTrue(Zend_Auth::getInstance()->hasIdentity()); // FAILED!
    }
}
Foi útil?

Solução

Doing that is in conflict with unit testing idea. Tests are in isolation. You don't pass any states between them. Use fixtures for setting the environment. If you test a Model don't use ControllerTestCase. Use PHPUnit_Framework_TestCase instead.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top