Summer Sale! All accounts are 50% off this week.

Shivamyadav's avatar

getting error .

error

InvalidArgumentException: Unable to locate factory for [App\Models\User].

running this test i get the error

public function test_a_project_requires_a_title()
    {
        $user = factory(User::class)->create();
        $this->actingAs($user);
        $this->withoutExceptionHandling();
        $attributes = Project::factory()->raw(['title' => '']);
        $this->post('/projects', $attributes)->assertSessionHasErrors('title');
    }
0 likes
5 replies
vincent15000's avatar

Have you created a factory ? Have you declared it in your test file ?

Shivamyadav's avatar

@vincent15000 yea , here it is usersFactory

public function definition()
    {
        return [
            'name' => fake()->name(),
            'email' => fake()->unique()->safeEmail(),
            'email_verified_at' => now(),
            'password' => 'yIXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
            'remember_token' => Str::random(10),
        ];
    }

and how to declare it in a test file?

1 like
Shivamyadav's avatar

@vincent15000 now its telling me that , title field is required

  public function test_a_project_requires_a_title()
    {
        
        $user = User::factory()->create();
        $this->actingAs($user);
        // parent::setUp();
        $this->withoutExceptionHandling();
        $attributes = Project::factory()->raw(['title' => '']);
        $this->post('/projects', $attributes)->assertSessionHasErrors('title');
    }
1 like

Please or to participate in this conversation.