Open gcavana opened 7 years ago
Hey @gcavana. That's an interesting question, my guess is that the first step produces some side-effects that are conflicting with the 2nd request. That is why we often have to restart the Symfony kernel across requests (it's the default in Symfony's FrameworkBundle Client
).
I can't tell you what's wrong with that small amount of details, but 2 things: ensure that your kernel is restarted between your scenarios. If not, using var_dump
s or any debugger, have a look if anything is calling setToken
with a null value on your SecurityStorage (with an xdebug_print_function_stack()
function call if you'll see who is calling it easily). If all of that do not give you the answer, could you put somewhere a bit of code providing this problem and I can have a look.
Thanks for the quick reply @sroze ! I'm gonna use xdebug to find the caller and get back to you if i found something that can help.
Hi everyone,
I'm posting this issue from stackoverflow as i've got the same problem and no one seems do understand why this is happening. Maybe you can give us more insights on this one.
Stack overflow issue
In our Symfony applications we have custom code that handles authentication. It's based on top of thephpleague/oauth2-server.
We have 2 types of authentication, both of which end up calling TokenStorage::setToken().
All this works perfectly.
Now we decided to add some Behat tests to our bundle:
In order to test the Then steps, I need access to the TokenStorage in my Contexts because I basically want to test if the user has the correct security role:
My context looks like this:
What happens is:
if I run only the first scenario, it works OK if I run only the second scenario, it works OK if I run both of them, then on the 2nd scenario I get the error Call to a member function getRoles() on a non-object Why does this happen ? How can I make it work correctly ?
My versions are:
My thinking was that, by explicitly retrieving TokenStorage before each scenario, I would get a fresh instance each time and therefore it would work.
However, it behaved exactly the same :( .
What am I missing?