Courses

Creating a Quiz System with Laravel 10 + Livewire 3: Step-by-Step

In the next couple of lessons, we'll add automated tests to ensure that our app works as expected. This first test will be to check if only the admin user can access some parts of the application.

admin routes tests

To write tests, for the data we will use Factories.

For this test, first, we will add a factory callback to the UserFactory called admin. This way when we will create a user which needs to be an admin we will be able to chain the admin() method to the factory call.

database/factories/UserFactory.php:

class UserFactory extends Factory
{
// ...
public function admin(): static
{
return $this->afterCreating(fn (User $user) => $user->update(['is_admin' => true]));
}
}

Now we can create a feature test...

This lesson is only for Premium Members.
Want to access all lessons of this course?

You also get:

  • 59 courses (1056 lessons, 44 h 09 min total)
  • Premium tutorials
  • Access to repositories
  • Private Discord