Challenge - 5 Problems
Laravel Feature Test Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What does this Laravel feature test do?
Consider this Laravel feature test code. What is the expected behavior when this test runs?
Laravel
public function test_homepage_shows_welcome_message()
{
$response = $this->get('/');
$response->assertStatus(200);
$response->assertSee('Welcome to our site');
}Attempts:
2 left
💡 Hint
Look at the methods get(), assertStatus(), and assertSee() to understand what is tested.
✗ Incorrect
The test sends a GET request to '/' and expects a 200 OK status. It also checks that the response contains the text 'Welcome to our site'.
📝 Syntax
intermediate2:00remaining
Identify the syntax error in this Laravel feature test
Which option correctly fixes the syntax error in this test method?
Laravel
public function test_user_can_login()
{
$response = $this->post('/login', [
'email' => 'user@example.com',
'password' => 'secret'
]);
$response->assertRedirect('/dashboard');
}Attempts:
2 left
💡 Hint
Check the end of the assertRedirect line for missing punctuation.
✗ Incorrect
The missing semicolon after the assertRedirect() call causes a syntax error. Adding it fixes the problem.
❓ state_output
advanced2:00remaining
What is the state of the database after this feature test runs?
Given this Laravel feature test that creates a user, what will be the number of users in the database after the test completes?
Laravel
public function test_user_creation()
{
$this->post('/users', [
'name' => 'Alice',
'email' => 'alice@example.com',
'password' => 'password123'
]);
$this->assertDatabaseHas('users', ['email' => 'alice@example.com']);
}Attempts:
2 left
💡 Hint
Laravel feature tests use database transactions by default to isolate tests.
✗ Incorrect
Laravel feature tests wrap each test in a database transaction that is rolled back after the test completes, ensuring test isolation and no persistent data changes.
🔧 Debug
advanced2:00remaining
Why does this Laravel feature test fail?
This test is supposed to check that a guest user is redirected to login when accessing /dashboard. Why does it fail?
Laravel
public function test_guest_redirected_to_login()
{
$response = $this->get('/dashboard');
$response->assertStatus(200);
$response->assertSee('Login');
}Attempts:
2 left
💡 Hint
Check the expected HTTP status code for redirects.
✗ Incorrect
Guests accessing /dashboard are redirected to login with a 302 status. The test expects 200, so it fails.
🧠 Conceptual
expert2:00remaining
Which option best describes Laravel feature tests?
Choose the statement that correctly explains the purpose and behavior of Laravel feature tests.
Attempts:
2 left
💡 Hint
Think about what 'feature' means in testing Laravel apps.
✗ Incorrect
Feature tests simulate real user actions by sending HTTP requests and checking responses, covering multiple layers.