These are chat archives for Behat/Behat
I am starting using Behat and I was thinking what is the correct way to do something like this:
I am testing system behaviour with Behat (the domain, not web) and i want to test behaviour that uses UserService class. UserService takes UserRepository (Interface) as an argument. Should i create the UserService object in the context or should i take it from some dependency injection container (which i currently don't have since i want to model the domain first)? Or should i maybe create a factory to construct the UserService? Should I mock those dependencies?
The problem here is, that there may be multiple implementations of UserRepository and i want to test the one the system uses (hence taking UserService from DI container). I do not know which implementation i am going to use at the time of writing the feature file/context. Probably just some dummy FilesystemUserRepository just to pass the tests.
If I used the FilesystemUserRepository in contexts, then after i decide to move to DatabaseUserRepository later in development i would have to rewrite all the contexts that use UserService class.
Is there some best practice how to do this?
@everzet that was my thinking initially, but wouldn't this require me to change all contexts (the part where i'll resolve the deps graph) when i settle for final implementation of the repository in question. However, at this point i will most likely have chosen a DIC.
So maybe in early stages i should use in-memory repositories and resolve dependencies manually and after i settle for a specific DIC I should use Behat extension for that specific DIC to pass dependencies into contexts... Decisions, decisions...