post('posts'); $response->assertSessionHasErrors('title')->assertStatus(302); // Post with title should succeed $response = $this->post('posts', ['title' => 'Some title']); $response->assertStatus(200); // Post with the same title should fail because it's not unique $response = $this->post('posts', ['title' => 'Some title']); $response->assertSessionHasErrors('title')->assertStatus(302); } public function test_array_validation() { $user = User::factory()->create(); // Post without name and email should fail $response = $this->actingAs($user)->post('profile'); $response->assertStatus(302); // Post with name and email should succeed $response = $this->actingAs($user)->post('profile', [ 'profile' => [ 'name' => 'Some name', 'email' => 'some@email.com' ] ]); $response->assertStatus(200); } public function test_validation_errors_shown_in_blade() { // Post without name and description should fail $response = $this->followingRedirects()->post('projects'); $response->assertStatus(200); $response->assertSee('The name field is required.'); $response->assertSee('The description field is required.'); } }