Skip to content

Using Sessions in WebTestCase not working #45662

Discussion options

You must be logged in to vote

Hey there, I found a way to access the controller session in my tests. It is heavily based on insights from @chyshyya and from your own code @DigitalTimK, thanks to both of you 🙏

I have to tell you that I'm using Symfony 6.1 and my solution may not totally fix your case as you're using Symfony 5.4. I hope it will!

There were two missing things in your previous attempts:

  1. the cookie domain had to be set (e.g. localhost)
  2. new MockFileSessionStorage() didn't create the session file in the same directory as the one of the controller session (it took me a while to figure it out), which is defined by the session.save_path configuration key

I extracted my code in a trait so it can be easily reus…

Replies: 2 comments 16 replies

Comment options

You must be logged in to vote
10 replies
@chyshyya
Comment options

@DigitalTimK
Comment options

@DigitalTimK
Comment options

@arderyp
Comment options

@DigitalTimK
Comment options

Comment options

You must be logged in to vote
6 replies
@marien-probesys
Comment options

@crtl
Comment options

@marien-probesys
Comment options

@crtl
Comment options

@marien-probesys
Comment options

Answer selected by DigitalTimK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants