farshadf's avatar

simple create test with logged in user in laravel 5

i want to write a test for my comment model but for making that the user must be logged in i want to know how people write create tests in laravel because when i make it with the below method :

   $file = UploadedFile::fake()->create('image.jpg');

        $data = [
            'title' => $this->faker->word,
            'link' => $this->faker->url,
            'image' => $file,
        ];
      
        $employee = factory(User::class)->create();
      
        $this
            ->actingAs($employee, 'admin')
            ->post(route('admin.carousel.store'), $data)
            ->assertStatus(302)
            ->assertRedirect(route('admin.carousel.index'))
            ->assertSessionHas('message', 'Create carousel successful!');

and when i make it with the below command i cant understand really if its created or not :

  $this->actingAs($user);
        $this->createMock(Comment::class);

so i really want to know how to check the creation of the model in laravel .

0 likes
1 reply

Please or to participate in this conversation.