0
0
Laravelframework~10 mins

HTTP test assertions in Laravel - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to assert the HTTP response status is 200.

Laravel
response()->get('/home')->assert[1](200);
Drag options to blanks, or click blank then click option'
AcheckStatus
BStatus
Cstatus
DverifyStatus
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method that does not exist like 'status' or 'checkStatus'.
Forgetting to call the method with parentheses.
2fill in blank
medium

Complete the code to assert the response contains the text 'Welcome'.

Laravel
response()->get('/')->assert[1]('Welcome');
Drag options to blanks, or click blank then click option'
AcheckText
BhasText
CcontainsText
DSee
Attempts:
3 left
💡 Hint
Common Mistakes
Using methods that do not exist like 'hasText' or 'checkText'.
Confusing assertSee with assertDontSee.
3fill in blank
hard

Complete the code to assert the response JSON has a key 'success'.

Laravel
response()->get('/api/test')->assert[1](['success']);
Drag options to blanks, or click blank then click option'
AJsonStructure
BJsonHas
ChasJsonKey
DJsonFragment
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like 'JsonHas' or 'hasJsonKey'.
Passing a string instead of an array.
4fill in blank
hard

Fill both blanks to assert the response redirects to '/dashboard' and has a session key 'status'.

Laravel
response()->post('/login')->assert[1]('/dashboard')->assert[2]('status');
Drag options to blanks, or click blank then click option'
AredirectTo
BRedirect
CSessionHas
DhasSession
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method names like 'redirectTo' or 'hasSession'.
Mixing up redirect and session assertions.
5fill in blank
hard

Fill all three blanks to assert the response has JSON with key 'user', the 'name' field equals 'Alice', and status 201.

Laravel
response()->post('/api/users')->assert[1](['user'])->assertJsonPath('user.name', [2])->assert[3](201);
Drag options to blanks, or click blank then click option'
AJsonStructure
B'Alice'
CStatus
DJsonFragment
Attempts:
3 left
💡 Hint
Common Mistakes
Using assertJsonFragment instead of assertJsonStructure for keys.
Forgetting quotes around 'Alice'.
Mixing up status assertion method.