The problem you have is that the iAmLoggedInAsUserId method performs calls on the laravel framework directly, where as your subsequent instructions are browser/mink based. This is like having a PHP script which you run from the command line which sets (for its execution) the logged in user to 123, and then going to a web browser - user 123 wouldn't be logged in in that context.
You need to find a way for the code-based authentication to persist to your browser test.
Possible options:
- An aggregate instruction for iAmLoggedInAsUserId which goes to the login page, and performs the login.
- Hijack the session being used by mink, and update it to be logged in
- A local-only work around which lets you, say, set a header to contain a user ID, and your code, only when running locally, uses this as the logged in user
Ideally, you should write a test to test logging in, however that is structured (i.e. option 1) and then re-use that for your tests which require a logged in user. The other two options are simply ideas if you use-case doesn't permit the first.
Edit: The following is an example aggregate instruction, this particular version requires the user exist in the system. You could however force a user to exist before hand, and if it was added as part of the test, delete it once the test is completed using the @AfterFeature hook:
/**
* @Given /I am logged in with the username "([^"]*)" and password "([^"]*)"/
*/
public function loginWithEmailAndPassword($username, $password)
{
//$this->ensureUserExistsWithEmailAndPassword($email, $password);
return array(
new Behat\Behat\Context\Step\Given("I am on \"/login\""),
new Behat\Behat\Context\Step\When("I fill in \"login_username\" with \"$username\""),
new Behat\Behat\Context\Step\When("I fill in \"login_password\" with \"$password\""),
new Behat\Behat\Context\Step\When("I press \"Login\""),
new Behat\Behat\Context\Step\Then("I should see \"Welcome\"")
);
}