I am coding a Laravel package, and I have written functional testing. For that, I need to seed users, using factories.
In my config, I have :
'user' => [
'table' => 'users',
'primary_key' => 'id',
'foreign_key' => 'user_id',
'model' => App\Models\User::class,
],
But in my test package, App\Models\User is not defined, because it is only defined in main laravel project.
So, I tried to use use Illuminate\Foundation\Auth\User instead of App\Models\User in my tests, but I get a message :
InvalidArgumentException: Unable to locate factory for [Illuminate\Foundation\Auth\User].
Which I understand. But I cannot find a way to solve my issue a this point.
In my package's ServiceProvider, I have :
$this->publishes([__DIR__ . '/../database/seeders' => $this->app->databasePath().'/seeders'], 'laravel-tournaments');
$this->publishes([__DIR__.'/../database/factories' => $this->app->databasePath().'/factories'], 'laravel-tournaments');
$this->publishes([__DIR__.'/../config/laravel-tournaments.php' => config_path('laravel-tournaments.php')], 'laravel-tournaments');
Any idea ?
I found an answer examinating Laravel Permission package.
For functional testing, inside test folder, they put a TestModels/ folder with a copy of User class.
With trait
hasRoles:All the models than depends on User should also be duplicated there