如何从测试内部销毁 CakePHP 会话?
我发现如果您登录,从浏览器运行时测试会失败。我需要确保在运行此测试之前清除会话。有没有一种简单的方法可以从测试中清除 CakePHP 会话?
我尝试调用 Session::Destroy();但测试似乎无法获得会话的可见性。
也许我试图错误地导入会话? 我正在使用: App::import('Core', 'Session');
I found a test that fails when run from a browser if you are logged in. I need to make sure the session is cleared out before running this test. Is there an easy way to clear the CakePHP session from within a test?
I tried calling Session::Destroy(); but the test cannot seem to get visibility of Session.
Maybe I am trying to import Session incorrectly?
I am using: App::import('Core', 'Session');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该模拟 Session 组件。 Mark Story 自己写了一篇文章,展示如何测试控制器。
You should mock the Session component. Mark Story himself wrote an article showing how to test controllers.
我相信 gustavotkg 是正确的。我们应该使用模拟对象。不幸的是,按照代码设置的方式执行此操作并不完全简单。我将不得不回去重新做一些事情。对于临时修复,这就是我所做的:
I believe gustavotkg is correct. We should be using mock objects. Unfortunately, it will not be completely straight forward to do this the way the code was set up. I will have to go back and rework some things. For a temporary fix this is what I did:
希望这可以帮助你..
hope this can help you..