MinkExtension icon indicating copy to clipboard operation
MinkExtension copied to clipboard

Specify session name to get

Open kochen opened this issue 6 years ago • 19 comments

When using in combination with Behat/MinkExtension and setting the Symfony cache:

        Behat\MinkExtension:
            sessions:
                default:
                    symfony: ~

you get:

Specify session name to get  

setting other sessions like goutte (and its corresponding driver) results in the same issue.

kochen avatar Apr 19 '18 08:04 kochen

For reference: https://github.com/FriendsOfBehat/SymfonyExtension/issues/30

kochen avatar Apr 19 '18 08:04 kochen

Same issue with Behat/Symfony2Extension

kochen avatar Apr 23 '18 07:04 kochen

@everzet @stof any news about this error ? I've got same error on sf4.1

loic425 avatar Jun 29 '18 13:06 loic425

Managed to narrow it down to prepareDefaultMinkSession (namely setDefaultSessionName) not being called and therefor default session not being set, so when calling getSession($name=null) it won't find any default session.

kochen avatar Jul 26 '18 12:07 kochen

Please provide a reproducing case

stof avatar Jul 26 '18 12:07 stof

@stof

<service id="mink.default_session" class="Behat\Mink\Session" lazy="true" public="false">
    <factory service="__behat__.mink" method="getSession" />
</service>
        Behat\MinkExtension:
            base_url: "http://localhost:8080/"
            default_session: symfony
            sessions:
                symfony:
                    symfony: ~

as mentioned above, this happens with every session driver...

kochen avatar Jul 26 '18 12:07 kochen

well, if you create your own service getting the session, this service might get instantiated too early compared to the time where we configure the default session for this scneario. Thus, it does not really make sense, as the default session can change at any scenario.

stof avatar Jul 26 '18 13:07 stof

sure, but the problem is that neither prepareDefaultMinkSession nor setDefaultSessionName are being called at all (regardless of the "right timing")

kochen avatar Jul 26 '18 13:07 kochen

Well, please provide a reproducing case (and the code you gave above is not a reproducing case, as I have no idea where this XML is meant to go and where the __behat__.mink service is coming from)

stof avatar Jul 26 '18 16:07 stof

@kochen You can create a small project on github to expose that. If you don't have enough time I probably can do that... but later...

loic425 avatar Jul 27 '18 08:07 loic425

@stof @loic425 took a while but here it is: https://github.com/kochen/behat-mink-session

kochen avatar Oct 17 '18 20:10 kochen

I've added travis-ci builds so it's easy to see the error: https://travis-ci.org/kochen/behat-mink-session/jobs/443045087#L485

kochen avatar Oct 18 '18 07:10 kochen

@kochen @stof I've same problem here on this pull-request with travis log here

loic425 avatar Oct 18 '18 12:10 loic425

@stof In SessionListener, prepareDefaultMinkSession is not called. I have this problem only when I remove symfony/symfony dependency.

loic425 avatar Oct 19 '18 13:10 loic425

@stof In SessionListener, prepareDefaultMinkSession is not called. I have this problem only when I remove symfony/symfony dependency.

Yes, I mentioned that here: https://github.com/Behat/MinkExtension/issues/321#issuecomment-408077976 but it gives a good starting point, if it does work when symfony/symfony is required. Now we need to figure out what is actually making that call and how can we ensure it is also being called without that (huge) package...

kochen avatar Oct 20 '18 08:10 kochen

I found it! This is not due to mink extension.

@kochen you just have to add symfony/proxy-manager-bridge to handle lazy option. https://symfony.com/doc/current/service_container/lazy_services.html https://github.com/Monofony/SymfonyStarter/pull/74

loic425 avatar Dec 06 '18 11:12 loic425

@stof You can close this issue.

loic425 avatar Dec 06 '18 11:12 loic425

@loic425 this indeed seems to solve the issue, but I wouldn't close the issue it just yet. @stof I think we need to document/suggest/guide users of the packages about this.

kochen avatar Dec 06 '18 13:12 kochen

@kochen This is not a common case. This is due to the way Sylius did with its "mink.default_session" service.

<service id="mink.default_session" class="Behat\Mink\Session" lazy="true" public="false">
    <factory service="__behat__.mink" method="getSession" />
</service>

But this package is already on Sylius.

loic425 avatar Dec 06 '18 13:12 loic425