In this episode, we get our Laravel development environment all set up so we can start writing tests using Pest. We kick things off by spinning up a fresh Laravel project (we're calling it "Book Friends") and running through the usual setup—configuring our .env
database settings, running migrations, and making sure everything works out of the box.
Next, we take a quick look at Laravel's default testing setup using PHPUnit, but we don't stick with that too long. Instead, we clean out the sample tests and move on to installing Pest and the Laravel Pest plugin. Once everything's installed, we walk through the new files Pest adds (like Pest.php
) and explain how some of those bits work under the hood.
We demonstrate how to generate new test files, show the difference in syntax between PHPUnit (class-based) and Pest (function-based, like test()
and it()
), and talk through a few different ways to make assertions in Pest. You'll see exactly how writing tests in Pest can be a bit more fun and readable!
Before wrapping up, we make sure to switch our test database settings to use SQLite in-memory. This is a super important step so our real database doesn't get trashed when we start running tests, especially when factories and migrations get involved.
All in all, by the end of this episode, your Laravel app will be ready to roll with Pest and you'll understand how the pieces fit together. Next up: actually building out some app features and writing real-world tests!