开发者

Isolating Zend_Session in PHPUnit tests

I am testing authentification functionality of my site. Zend_Auth is using as authorization engine. But auth status remains between tests and I need to write 'logout' in every tearDown.

Now everything is all right. But the problem is following. As for I know Zend_Auth uses Zend_Session for storing auth data. So, session is common for all tests. I am affraid that in future it can cause problems.

Can you tell me what is the best practice to make sessions for each test isolated?

Now I can imagine only manually starting session in setUp and stop in tearDown开发者_JS百科. But I have many tests and implementing this can take a lot of time.


PHPUnit allows you to define a shared fixture (a common set up) for a whole test suite. However, this solution just masks a flaw in the design of the tests, since it doesn't address their dependency on a common global state. A better solution is to use test doubles, creating custom stubs of certain classes to control the behaviour of chosen parts of the system.

In this case you could try to create a stub of Zend_Auth so that it skips the use of Zend_Session and returns the desired permissions for each unit test.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜