douju2474
douju2474
2012-09-29 20:31
浏览 48
已采纳

Zend_Test,身份和cookies

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!
    }
}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongyuqie4322
    dongyuqie4322 2012-09-29 20:37
    已采纳

    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.

    点赞 评论

相关推荐