Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Important: Test "Happy" and "Sad" Paths

Premium
3 min read

The final part of this "philosophical" course section on "what to test" is about the happy/unhappy paths. The example is from our tests.

test('admin can see products create button', function () {
$admin = User::factory()->create(['is_admin' => true]);
 
actingAs($admin)
->get('/products')
->assertStatus(200)
->assertSee('Add new product');
});
 
test('non admin cannot see products create button', function () {
actingAs($this->user)
->get('/products')
->assertStatus(200)
->assertDontSee('Add new product');
});

For example, we covered the create button for products in previous lessons.

I added two tests for the opposite cases:

  • The "happy path": if I'm an admin, I can see the button
  • The "non-happy path": if I'm not an admin, I cannot see the products create button.

And this is important.

Quite often...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 14 min)

You also get:

54 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

No comments yet…