开发者

How to clear PHP APC from a Selenium test?

开发者 https://www.devze.com 2023-01-20 02:00 出处:网络
In my PHP Zend Framework application, I am using APC to cache certain repeat requests to the database. Within the application, I can clear the cache with this command:apc_clear_cache(\'user\')

In my PHP Zend Framework application, I am using APC to cache certain repeat requests to the database. Within the application, I can clear the cache with this command:apc_clear_cache('user')

I am also running PHPUnit Selenium tests against this application. Before adding APC, I had no problems. I have a test that adds开发者_如何学Go a test user to the database (in setup), logs them into the application (in the test), and removes the user record from the database (in teardown). This same routine happens in all the tests, since you need to be logged in to use certain features of the application. Now that APC is in place, APC is caching the first user that is created, but doesn't clear the cache when the user is re-created, which means the login only works on the first test.

I need to figure out a way to clear the cache from my Selenium test. The only way I could think of how to do this was to create a controller action that is wide open to the public to access, that way, from my test I could open /cache/clear and it would clear the cache. I tried this approach and it worked, but this approach doesn't seem very practical since anyone can access that URL.

What should be my solution to this situation?


Well, clear your cache in TearDown() and SetUp() then?


Calling a script is the only way, since you have to run apc_clear in the Apache context, rather than the shell context. You simply have to secure it, ideally obfuscate a bit its existence. As long as there is a password protection or a client lock (restricting to specific IP addresses) there's no problem doing that.

0

精彩评论

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