Challenge - 5 Problems
Laravel HTTP Test Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What does this Laravel HTTP test assertion check?
Consider this Laravel test code snippet:
What does the
$response = $this->get('/home');
$response->assertStatus(200);What does the
assertStatus(200) method verify in this test?Laravel
$response = $this->get('/home'); $response->assertStatus(200);
Attempts:
2 left
💡 Hint
The number inside assertStatus refers to the HTTP status code returned by the server.
✗ Incorrect
The assertStatus method checks the HTTP status code returned by the response. Passing 200 means the test expects a successful OK response.
📝 Syntax
intermediate2:00remaining
Which option correctly asserts JSON structure in Laravel HTTP test?
You want to test that the JSON response contains a key 'user' with a nested key 'name'. Which assertion syntax is correct?
Laravel
$response = $this->get('/api/user');Attempts:
2 left
💡 Hint
Use assertJson with an array matching the expected JSON structure.
✗ Incorrect
assertJson expects an array that matches part of the JSON response. Nested arrays represent nested JSON objects.
🔧 Debug
advanced2:00remaining
Why does this Laravel HTTP test fail with a 500 error?
Given this test code:
The test fails with a 500 Internal Server Error instead of 302 redirect. What is the most likely cause?
$response = $this->post('/login', ['email' => 'user@example.com']);
$response->assertStatus(302);The test fails with a 500 Internal Server Error instead of 302 redirect. What is the most likely cause?
Laravel
$response = $this->post('/login', ['email' => 'user@example.com']); $response->assertStatus(302);
Attempts:
2 left
💡 Hint
Check if all required form fields are included in the POST data.
✗ Incorrect
A 500 error often means the server code crashed. Missing required input like 'password' can cause this in login logic.
❓ state_output
advanced2:00remaining
What is the value of $response->headers->get('Content-Type') after this test?
In a Laravel test:
If the API returns JSON, what is the expected value of
$response = $this->get('/api/data');
$contentType = $response->headers->get('Content-Type');If the API returns JSON, what is the expected value of
$contentType?Laravel
$response = $this->get('/api/data'); $contentType = $response->headers->get('Content-Type');
Attempts:
2 left
💡 Hint
APIs returning JSON usually set Content-Type to application/json.
✗ Incorrect
Laravel sets the Content-Type header to 'application/json; charset=utf-8' for JSON responses by default.
🧠 Conceptual
expert2:00remaining
Which Laravel HTTP test assertion ensures a redirect to a named route?
You want to test that a response redirects to a route named 'dashboard'. Which assertion method and argument correctly verify this?
Laravel
$response = $this->post('/login', ['email' => 'user@example.com', 'password' => 'secret']);
Attempts:
2 left
💡 Hint
Use the route() helper to get the URL for a named route.
✗ Incorrect
assertRedirect expects a URL. Using route('dashboard') generates the URL for the named route 'dashboard'.