如何从 Selenium 测试中清除 PHP APC?
在我的 PHP Zend Framework 应用程序中,我使用 APC 缓存对数据库的某些重复请求。在应用程序中,我可以使用以下命令清除缓存:apc_clear_cache('user')
我还针对此应用程序运行 PHPUnit Selenium 测试。在添加 APC 之前,我没有任何问题。我有一个测试,将测试用户添加到数据库(在设置中),将其登录到应用程序(在测试中),并从数据库中删除用户记录(在拆卸中)。所有测试中都会发生相同的例程,因为您需要登录才能使用应用程序的某些功能。现在 APC 已就位,APC 正在缓存创建的第一个用户,但在重新创建用户时不会清除缓存,这意味着登录仅在第一次测试时有效。
我需要找到一种方法来清除 Selenium 测试中的缓存。我能想到的唯一方法是创建一个向公众开放访问的控制器操作,这样,从我的测试中我可以打开 /cache/clear
并且它会清除缓存。我尝试了这种方法并且它有效,但这种方法似乎不太实用,因为任何人都可以访问该 URL。
对于这种情况我应该采取什么解决方案?
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 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那么,清除
TearDown()
和SetUp()
中的缓存吗?Well, clear your cache in
TearDown()
andSetUp()
then?调用脚本是唯一的方法,因为您必须在 Apache 上下文中运行 apc_clear,而不是 shell 上下文。你只需要保护它,最好稍微混淆它的存在。只要有密码保护或客户端锁定(限制特定的 IP 地址),这样做就没有问题。
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.