'How to use laravel factory with behat?

I am learning the BDD method in a laravel 9 context project.

I added the behat dependencies. And when I run a simple test case : it works fine.

Now I want to go deeper. I have this basic scenario :

enter image description here

And the context for the highlighted step (the authentication) is :

/**
 * @Given I am authenticated with the role :arg1
 */
public function iAmAuthenticatedWithTheRole(string $roleId)
{
    $school = School::factory()->create();
    $user = User::factory()->create(['school_id' => $school->id, 'role_id' => $roleId]);
    $this->be($user);
}

When I run the test, it fails at the step to create a fake school. With this error :

Unknown format "word" (InvalidArgumentException)

But this school factory works fine in a traditional test. So I think that the "faker" library is not found or something like that. But what ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source