Behat, login and fixtures

January 30, 2014

I want to use behat for some of the  testing of a new project and I  found a thing that’s not so easy to implement: actual login without a registration form

The project right now doesn’t have a proper registration form, so I cannot use the registration process, also I don’t want to be tied to a “register” functionality that’s not yet required from the project.

I tried mocking the user, but injecting a “fake” UserToken in the container proved to be a dead end

I found a viable solution in using Fixtures and specifically by using the usermanager to automatically store a proper user

The tricky part has been injecting the container in the Fixture class, since using the method explained in the official documentation simply fails

Official docs say that you should simple implement ContainerAwareInterface and the setContainer method should be called automaticallly from Symfony itself. This is simply not the case. I didn’t investigate further and opted for not implementing the ContainerAwareInterface and instead explicitly injecting the needed services when instantiating the Fixture class from inside my test

Having a Container available made it simple to use it to obtain a proper user, fill it in with my values and store it

At this point I can test the  log in functionality using behat without actually needing an externally reachable way to create users.


Tags: , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

ERROR: si-captcha.php plugin says GD image support not detected in PHP!

Contact your web host and ask them why GD image support is not enabled for PHP.

ERROR: si-captcha.php plugin says imagepng function not detected in PHP!

Contact your web host and ask them why imagepng function is not enabled for PHP.