Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[FrameworkBundle] Prepare session in functionnal tests#21352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
cyve wants to merge1 commit intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromcyve:get-session-in-test

Conversation

cyve
Copy link

@cyvecyve commentedSep 6, 2025

Allow to setup session before performing a request in PHPUnit functionnal tests

Code PR:symfony/symfony#61110

@carsonbotcarsonbot added this to the7.4 milestoneSep 6, 2025
@carsonbotcarsonbot changed the title[WCM][FrameworkBundle] Prepare session in functionnal tests[FrameworkBundle][WCM] Prepare session in functionnal testsSep 6, 2025
@javiereguiluzjaviereguiluz added the Waiting Code MergeDocs for features pending to be merged labelSep 11, 2025
@carsonbotcarsonbot modified the milestones:7.4,nextSep 11, 2025
fabpot added a commit to symfony/symfony that referenced this pull requestSep 13, 2025
… (cyve)This PR was merged into the 7.4 branch.Discussion----------[FrameworkBundle] Prepare session in functionnal tests| Q             | A| ------------- | ---| Branch?       | 7.4| Bug fix?      | no| New feature?  | yes| Deprecations? | no| Issues        |Fix#46023| License       | MIT| Doc PR |symfony/symfony-docs#21352 |Hello,I propose to add a `getSession()` method to the `KernelBrowser` class 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 the `loginUser()` method. Then, the session could be preset either before or after the login, without risking to be overwritten.```phppublic function testForm(){    $client = self::createClient();    $client->loginUser(new InMemoryUser('admin', null));    $session = $client->getSession();    $session->set('_csrf/form', '123456789');    $session->set('foo', 'bar');    $session->save();    $client->request('POST', '/form', ['form' => ['_token' => '123456789']]);}```In this example, the session will contain :```phparray:3 [  "_security_main" => "O:52:"Symfony\Bundle\FrameworkBundle\Test\TestBrowserToken":2:{i:0;s:4:"main";i:1;a:5:{i:0;O:49:"Symfony\Component\Security\Core\User\InMemoryUser":4:{s:59:"\x00Symfony\Component\Security\Core\User\InMemoryUser\x00username";s:5:"admin";s:59:"\x00Symfony\Component\Security\Core\User\InMemoryUser\x00password";N;s:56:"\x00Symfony\Component\Security\Core\User\InMemoryUser\x00roles";a:0:{}s:58:"\x00Symfony\Component\Security\Core\User\InMemoryUser\x00enabled";b:1;}i:1;b:1;i:2;N;i:3;a:0:{}i:4;a:0:{}}}",  "_csrf/form" => "123456789",  "foo" => "bar"]```Thanks in advance for your feedbacks 😄Commits-------a8f045f [FrameworkBundle] Add KernelBrowser::getSession()
symfony-splitter pushed a commit to symfony/framework-bundle that referenced this pull requestSep 13, 2025
… (cyve)This PR was merged into the 7.4 branch.Discussion----------[FrameworkBundle] Prepare session in functionnal tests| Q             | A| ------------- | ---| Branch?       | 7.4| Bug fix?      | no| New feature?  | yes| Deprecations? | no| Issues        | Fix #46023| License       | MIT| Doc PR |symfony/symfony-docs#21352 |Hello,I propose to add a `getSession()` method to the `KernelBrowser` class 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 the `loginUser()` method. Then, the session could be preset either before or after the login, without risking to be overwritten.```phppublic function testForm(){    $client = self::createClient();    $client->loginUser(new InMemoryUser('admin', null));    $session = $client->getSession();    $session->set('_csrf/form', '123456789');    $session->set('foo', 'bar');    $session->save();    $client->request('POST', '/form', ['form' => ['_token' => '123456789']]);}```In this example, the session will contain :```phparray:3 [  "_security_main" => "O:52:"Symfony\Bundle\FrameworkBundle\Test\TestBrowserToken":2:{i:0;s:4:"main";i:1;a:5:{i:0;O:49:"Symfony\Component\Security\Core\User\InMemoryUser":4:{s:59:"\x00Symfony\Component\Security\Core\User\InMemoryUser\x00username";s:5:"admin";s:59:"\x00Symfony\Component\Security\Core\User\InMemoryUser\x00password";N;s:56:"\x00Symfony\Component\Security\Core\User\InMemoryUser\x00roles";a:0:{}s:58:"\x00Symfony\Component\Security\Core\User\InMemoryUser\x00enabled";b:1;}i:1;b:1;i:2;N;i:3;a:0:{}i:4;a:0:{}}}",  "_csrf/form" => "123456789",  "foo" => "bar"]```Thanks in advance for your feedbacks 😄Commits-------a8f045fdbcb [FrameworkBundle] Add KernelBrowser::getSession()
@cyvecyve changed the title[FrameworkBundle][WCM] Prepare session in functionnal tests[FrameworkBundle] Prepare session in functionnal testsSep 13, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
FrameworkBundleStatus: Needs ReviewWaiting Code MergeDocs for features pending to be merged
Projects
None yet
Milestone
next
Development

Successfully merging this pull request may close these issues.

3 participants
@cyve@javiereguiluz@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp