In this article let’s see how we can use Factory states to write fluent test cases.
First, let’s see how does our test cases looks like without any factory states.
Basically, we are writing a test to check that the user cannot view any unpublished blog posts.
/**
* @test
*/
public function user_cannot_view_unpublished_post()
{
$post = factory(Post::class)->create([
'published_at' => null
]);
$resource = $this->get("/posts/" . $post->slug);
$resource->assertStatus(404);
}
#laravel #testing #php #web-development