Complete the code to define a basic test method in Laravel.
public function test_example() {
$response = $this->[1]('/');
$response->assertStatus(200);
}In Laravel testing, get is used to make a GET request to a route.
Complete the code to assert that the response contains specific text.
$response->assert[1]('Welcome');
The correct Laravel assertion to check if response contains text is assertSee.
Fix the error in the test method to correctly check database records.
$this->assertDatabaseHas('[1]', ['email' => 'user@example.com']);
The correct table name in Laravel is usually users without '_table'.
Fill both blanks to create a test that checks if a user is redirected after login.
public function test_redirect_after_login() {
$response = $this->post('/login', ['email' => 'user@example.com', 'password' => 'secret']);
$response->assert[1]('/home');
$this->assertAuthenticatedAs([2]);
}assertRedirect checks the redirect URL, and auth()->user() gets the authenticated user instance.
Fill all three blanks to write a test that creates a user, logs in, and checks the dashboard view.
public function test_dashboard_access() {
$user = User::factory()->[1]();
$this->actingAs($user);
$response = $this->[2]('/dashboard');
$response->assert[3]('Dashboard');
}create() saves a user to the database, get() makes a GET request, and assertSee() checks if the response contains the text.