Zend_Session Isolation in PHPUnit Tests

I am testing the authentication features of my site. Zend_Auth uses as an authorization mechanism. But auth status remains between tests, and I need to write "logout" in each tearDown.

Now everything is all right. But the problem is the following. As far as I know, Zend_Auth uses Zend_Session to store auth data. Thus, the session is common to all tests. I am afraid that this may cause problems in the future.

Can you tell me what is the best way to do sessions for each isolated test?

Now I can only imagine a manual start session in setUp and stop at tearDown. But I have a lot of tests, and implementing this can take a long time.

+4
source share
1 answer

PHPUnit allows you to define a common tool (general setup) for the entire test suite. However, this solution simply masks the flaw in the design of the tests, since it does not take into account their dependence on the general global state. The best solution is to use test twins by creating custom stubs for specific classes to control the behavior of selected parts of the system.

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

+1
source

Source: https://habr.com/ru/post/1310090/


All Articles