Chaeril's avatar

need help with factory test and phpunit

$roles = factory(App\Role::class, 5)->create();
$tags = factory(App\Tag::class, 20)->create();

when i run phpunit, i always got Error: Class 'Tests\Feature\App\Role' not found, I've tried to add use App\Role too but it does not work either. what am i missing?

0 likes
3 replies
Tray2's avatar
  1. Do you have a Role.php in your App directory?
  2. Does it have the correct namespace?
Krisell's avatar
Krisell
Best Answer
Level 28

The error says it's looking for Tests\Feature\App\Role. If you want App\Role, try $roles = factory(\App\Role::class, 5)->create();

In use-statements, App\Role is sufficient since it starts at the root, however then you need to update your usage to $roles = factory(Role::class, 5)->create();

Please or to participate in this conversation.