Complete the code to create a basic feature test class in Laravel.
<?php namespace Tests\Feature; use Tests\TestCase; class ExampleTest extends TestCase { public function test_basic_example() { $response = $this->[1]('/'); $response->assertStatus(200); } }
The get method sends a GET request to the given URL, which is common for basic feature tests.
Complete the code to assert that the response contains the text 'Welcome'.
$response = $this->get('/home'); $response->[1]('Welcome');
assertSeeText checks if the response contains the given plain text.
Fix the error in the test method to correctly test a POST request with data.
public function test_submit_form()
{
$response = $this->post('/submit', [1]);
$response->assertStatus(302);
}The POST data must be an associative array with keys matching form fields.
Fill both blanks to test that a user is authenticated and redirected after login.
public function test_user_login()
{
$user = User::factory()->create();
$response = $this->post('/login', ['email' => $user->email, 'password' => 'password']);
$response->assertRedirect([1]);
$this->assertAuthenticatedAs([2]);
}The test expects a redirect to '/dashboard' and checks the authenticated user matches the created user.
Fill all three blanks to create a feature test that checks JSON response structure and status.
public function test_api_response()
{
$response = $this->json([1], '/api/data');
$response->assertStatus([2])
->assertJsonStructure([3]);
}The test sends a GET JSON request, expects HTTP 200 status, and checks the JSON has 'data' and 'meta' keys.