lundi 31 octobre 2016

PHPUnit Laravel InvalidArgumentException: Unable to locate factory with name [default] [App\User]

I have a setup function in a test which does the following

function setUp()
{
    $this->user = factory(User::class)->create();
}

ofcourse I used "use App\User;" at the very top.

This is my model factory

/** @var \Illuminate\Database\Eloquent\Factory $factory */
$factory->define(App\User::class, function (Faker\Generator $faker) {
    static $password;

    return [
        'name' => $faker->name,
        'email' => $faker->unique()->safeEmail,
        'password' => $password ?: $password = bcrypt('secret'),
        'remember_token' => str_random(10),
    ];
});

When runnning phpunit i get the error

InvalidArgumentException: Unable to locate factory with name [default] [App\User].

HOWEVER: If I go to php artisan tinker an run

factory(User::class)->create();

it works ... I tried App\User::class and other stuff and even putting it inside the test directly instead of the setUp method. The weird part is that another factory within the same file is working.

Aucun commentaire:

Enregistrer un commentaire