create(['published_at' => now()->subDay()]); Post::factory()->draft()->create(); $response = $this->get(route('blog.index')); $response->assertOk(); $response->assertSee($published->title); $response->assertViewHas('posts', function ($posts) { return $posts->total() === 1; }); } public function test_index_excludes_future_scheduled_posts(): void { Post::factory()->create(['published_at' => now()->addDay()]); $response = $this->get(route('blog.index')); $response->assertOk(); $response->assertViewHas('posts', function ($posts) { return $posts->total() === 0; }); } public function test_show_displays_a_published_post(): void { $post = Post::factory()->create([ 'title' => 'How to Train Consistently', 'published_at' => now()->subDay(), ]); $response = $this->get(route('blog.show', $post->slug)); $response->assertOk(); $response->assertSee('How to Train Consistently'); } public function test_show_returns_404_for_a_draft_post(): void { $post = Post::factory()->draft()->create(); $response = $this->get(route('blog.show', $post->slug)); $response->assertNotFound(); } public function test_show_returns_404_for_unknown_slug(): void { $response = $this->get('/blog/does-not-exist'); $response->assertNotFound(); } }