Spatie presents:

Testing
Laravel

Updated for Pest v2

Are you...

Learn how to write quality tests in Pest and PHPUnit

Video still
Flying man
cover image testing laravel
149 USD
Buy course
Testing Laravel cover
Laravel Beyond Crud cover

Get Testing Laravel & Laravel Beyond CRUD
with a 20% discount!

279 USD
Buy bundle

VAT will be calculated during checkout by Paddle.
We support Purchasing Power Parity.

What will the course
get me?

  • Learn best practices for testing Laravel applications
  • Ship less bugs to production and refactor stuff with confidence
  • Get access to our demo application with test suites
  • Learn how to convert an existing PHPUnit test suite to Pest

Free Examples

Testing Tips
in your mailbox

Subscribe to Testing Tidbits, a free newsletter with small but handy testing techniques.

You'll receive a daily email for one week, and occassional updates for this course.

Sample episodes

The basics of testing

Before continuing, learn more about why testing your applications is so important.

You will learn how to write a test suite from scratch. We'll cover how to make sure your homepage works, how you can test form submissions, what the different types of tests are, and much more!

/** @test  */
public function it_can_handle_a_form_submission()
{
    $this
        ->post(route('contact.submit'), [
            'message' => 'Hello, PHPUnit!',
        ])
        ->assertRedirect(route('home'))
        ->assertSessionHasNoErrors();
}

Testing Laravel

After we've covered the basics, we'll show you how to tests policies, middlewares, controllers, mails, views, and all kinds of features. We'll cover snapshots testing, pragmatic mocks, how to test domain code, how to set up CI, and much more.

/** @test  */
public function the_command_will_publish_scheduled_posts()
{
    TestTime::freeze('Y-m-d H:i:s', '2021-01-01 00:00:00');

    $post = Post::factory()->create([
        'publish_date' => now()->addHour(),
        'published' => false,
    ]);

    // Travel to a second before the post should be published
    TestTime::addHour()->subSecond();

    $this->artisan(PublishScheduledPostsCommand::class);

    $this
        ->get(route('posts.show'), $post->slug))
        ->assertNotFound();

    // Travel to the time that a post should be published
    TestTime::addSecond();

    $this->artisan(PublishScheduledPostsCommand::class);

    $this
        ->get(route('posts.show'), $post->slug))
        ->assertSuccessful();

    $this->assertTrue($post->refresh()->published);
}

Let's Pest this

Pest is the new kid on the block in the PHP testing world that focuses on stellar developer experience. It's rapidly rising in popularity, and we believe it'll only grow in the near future. That's why we've recorded our entire course twice: first with PHPUnit, then with Pest v2 and all the awesome features it has to offer.

We'll also show you how to convert an existing PHPUnit test suite to Pest.

it('has a scope to retrieve all published blogposts', function() {
    $publishedBlogPost = BlogPost::factory()->published()->create();
    $draftBlogPost = BlogPost::factory()->draft()->create();

    $publishedBlogPosts = BlogPost::wherePublished()->get();

    expect($publishedBlogPosts)
        ->toHaveCount(1)
        ->and($publishedBlogPosts->first()->id)->toBe($publishedBlogPost->id);
});

Nothing inspires confidence while shipping like a good test suite. I'm thrilled Spatie is introducing a new generation of Laravel developers to the strong testing culture of the Laravel ecosystem.

Taylor Otwell
Taylor Otwell
Laravel Founder & Creator

Wish I had seen a video course like "Testing Laravel" years ago when was learning Laravel myself. It's the perfect starting point for developers that want to learn how to write tests in Laravel.

Nuno Maduro
Nuno Maduro
Pest creator & developer at Laravel

Anyone can show you how to write tests. A few can answer the question of what to test. Which is the real elephant in the room. Spatie has the experience and expertise to answer the big question. This course is going to have a huge impact on how Laravel developers test their apps.

Mohamed Said
Mohamed Said
Author & developer at Laravel

Table of contents

All videos are recorded in Pest and PHPUnit versions unless indicated otherwise

Getting started

  • Intro
  • Our first HTTP test
  • Using a database
  • Using factories
  • Factory relations
  • Testing a form
  • Authenticated testing
  • JSON assertions
  • Exploring the expectation API Pest
  • Automatically rerun tests Pest
  • Higher order tests Pest
  • Higher order expectations Pest

Mocking dependencies

  • Testing fakes
  • Mocking
  • Handcrafted mocks
  • Testing time

Testing Laravel in depth

  • Middleware tests
  • Validation in depth
  • Validation rule testing
  • Testing file uploads
  • Policy testing
  • Policies continued
  • Testing console applications
  • The HTTP facade
  • Testing blade components
  • Browser tests
  • Dusk in Depth
  • Testing Livewire
  • Testing Jobs
  • Custom factories

Configuring tests

  • Parallel testing PHPUnit
  • Data providers
  • Configuring database connections

Testing tidbits

  • Testing exceptions
  • Testing domain code
  • Trying out TDD
  • Refactoring with tests
  • Regression testing
  • Snapshot testing
  • Tests and CI
  • What's new in Pest v2 Pest

Converting an existing PHPUnit test suite to Pest Pest

  • Why use Pest?
  • Installing Pest
  • Using traits
  • Grouping tests
  • Using datasets
  • Rewriting the base testcase
  • Introducing higher order tests
  • Converting assertions to the expectation API

Free Testing Tips
in your mailbox

Subscribe to Testing Tidbits, a free newsletter with small but handy testing techniques.

You'll receive a daily email for one week, and occassional updates for this course.