[FrameworkBundle] Prepare session in functional tests#61110
Merged
Conversation
c470c19 to
989654b
Compare
alamirault
approved these changes
Jul 18, 2025
d8011a5 to
b4a8647
Compare
b4a8647 to
4be5343
Compare
|
Bumping this, as that would IMO be a great addition to the framework. Preparing the request with some session data before the request is emitted can be very useful to mock previous user interactions in multi-step operations. |
4be5343 to
2bf5391
Compare
Contributor
Author
|
I added a PR in the documentation : symfony/symfony-docs#21352 |
b2e1cc1 to
a4ebe76
Compare
nicolas-grekas
approved these changes
Sep 12, 2025
Comment on lines
+149
to
+150
| $session = $this->getSession(); | ||
| if (!$session instanceof SessionInterface) { |
Member
There was a problem hiding this comment.
Suggested change
| $session = $this->getSession(); | |
| if (!$session instanceof SessionInterface) { | |
| if (!$session = $this->getSession()) { |
| $session->set('foo', 'bar'); | ||
| $session->save(); | ||
|
|
||
| // prove remembered name from programmatically prepared session |
Member
There was a problem hiding this comment.
Suggested change
| // prove remembered name from programmatically prepared session | |
| // prove remembered name from programatically prepared session |
fabpot
approved these changes
Sep 13, 2025
| * Deprecate `Symfony\Bundle\FrameworkBundle\Console\Application::add()` in favor of `Symfony\Bundle\FrameworkBundle\Console\Application::addCommand()` | ||
| * Add `assertEmailAddressNotContains()` to the `MailerAssertionsTrait` | ||
| * Add `framework.type_info.aliases` option | ||
| * Add `KernelBrowser::getSession()` method |
Member
There was a problem hiding this comment.
Suggested change
| * Add `KernelBrowser::getSession()` method | |
| * Add `KernelBrowser::getSession()` |
a4ebe76 to
a8f045f
Compare
Member
|
Thank you @cyve. |
This was referenced Oct 27, 2025
Merged
Merged
javiereguiluz
added a commit
to symfony/symfony-docs
that referenced
this pull request
Feb 17, 2026
…yve) This PR was merged into the 7.4 branch. Discussion ---------- [FrameworkBundle] Prepare session in functional tests Allow to setup session before performing a request in PHPUnit functionnal tests Code PR: * symfony/symfony#61110 Commits ------- 4c96d19 [FrameworkBundle] Add KernelBrowser::getSession()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello,
I propose to add a
getSession()method to theKernelBrowserclass to be able to prepare the session before sending a HTTP request in a functionnal test. It could be used to preset CSRF tokens, A/B testing data, user preferences, or any stateful information required for the test.I also propose to use
getSession()in theloginUser()method. Then, the session could be preset either before or after the login, without risking to be overwritten.In this example, the session will contain :
Thanks in advance for your feedbacks 😄