Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to access Session variable #149

Open
cooldude77 opened this issue May 27, 2024 · 4 comments
Open

How to access Session variable #149

cooldude77 opened this issue May 27, 2024 · 4 comments

Comments

@cooldude77
Copy link

Hi,
For testing purposes , I need to access session and set a value to it .

The class Browser has marked session as protected . I could not find in documentation any reference to session in any method

Thanks

@nikophil
Copy link
Member

hello @cooldude77

by "session", do you mean "http session"? Browser does not deal with http session. And the method Browser::session() refers do the "mink session" which is a different concept

@cooldude77
Copy link
Author

Hey @nikophil ,

Sorry for not explaining it fully.

I wish to test how controller logic behave when I set a session variable ( for eg. a filled cart in a web shop or an empty cart).

Here I would like to set the session variable which I access in controller using RequestStack getRequest() method in my controller method and then getting the session from it. Based on values in session, controller performs a logic.

I understand that the browser does not have session because it is handled by Mink. Will that be the same session as I explained above and can I manipulate it somewhere in test case ?

Thanks.

@nikophil
Copy link
Member

currently, browser does not provide a way to manipulate the session. Maybe this could be a nice addition to this lib? ping @kbond

For now, maybe you could use this trick: symfony/symfony#45662 (comment)

@kbond
Copy link
Member

kbond commented Jun 1, 2024

Yes, this would be a nice addition.

You can currently access the "cookie jar":

$browser->use(CookieJar $cookies) {
    // ...
})

I use it successfully to expire the current session:

$browser->use(function(CookieJar $cookieJar) {
    $cookieJar->expire('MOCKSESSID');
})

It would be nice if we could do the following:

$browser->use(SessionInterface $session) {
    // ...
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants