symfony: [Session][Test] Configured cookie domain is not set
I’m having troubles doing functional testing with multiple domains. It’s a bit tricky, but I’ll try to explain:
BrowserKit puts cookies in a CookieJar, in a domain[path][cookie] hierarchy. The values for these 3 keys are obtained from Cookie objects, which is created by the TestSessionListener.
Herein lies the problem: the cookie params are obtained via session_get_cookie_params, which uses the php-ini cookie values. Normally these are properly set in the NativeSessionStorage, not so much in the MockArraySessionStorage. This in turn leads to all sorts of problems when testing features that require cookies on a subdomain, for example when you have a “my.domain.org” subdomain.
/cc @drak I believe you are the session-expert for Symfony 😉, do you have any ideas about this?
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 16 (9 by maintainers)
@drak I think the mock version of the storage should also use the
cookie_*options of the session to build its mocked storage. Otherwise, we will indeed face issue when needing to set the session cookie for a less specific domainI’m using the standard test configuration, mostly:
(this is not the complete config, obviously, only the relevant parts)
What I’m trying to do, via Behat/Mink is testing a simple login process:
While debugging, I see that the cookiejar has cookies for 3 domains:
Since
session_get_cookie_params()is used in theTestSessionListener, and the params are not set, the domain is used from the current request. This explains the 3 domains. When I test in a browser this is only the.domain.orgdomain, and it works properly. The test passes if I manually setcookie_domainto.domain.orgright beforesession_get_cookie_params()is used.Hopefully this explains it better, normally I’d write a clean test case which demonstrates this but this is not quite easy to set up, I’ll need some time to do so.