Interested in generating passive income? Join our partnership program and receive a commission on each new client referral. Learn more.
8 min read
Interested in generating passive income? Join our partnership program and receive a commission on each new client referral. Learn more.
The Laravel core team packed Laracon US with exciting new releases and updates. One of the standout moments was a new release introduced by Nuno Maduro - Laravel Pest 3.0. With the release of Pest 3, the framework introduces several new features to make the developer testing experience even more intuitive and developer-friendly.
So, if you didn’t get a chance to attend or watch the talks, let’s break down the highlights of Laravel Pest 3 and talk about all the key features behind it.
Laravel Pest 3 enhances team collaboration by rethinking the way we handle test todos for other collaborators. Instead of just using TODO@username to remind us of postponed tasks, Pest 3 now allows you to assign specific tests or groups of tests directly to team members, making it easy to delegate testing responsibilities.
One of the standout features in Pest 3 is the ability to assign GitHub issues directly to your tests. You can now assign a GitHub issue to each test so the whole team can see exactly which test corresponds to which issue. For example, if Issue 11 relates to one test and Issue 22 to another, this feature ensures that each test is clearly linked to its relevant GitHub issue. This also makes it easy to filter tests by an assignee or issue number, allowing teams to focus on the tests they’re responsible for or that relate to specific issues.
Pest 3 also lets you assign tasks to individual users. This is useful when organizing tests for different team members. Let’s take a look at the example:
// Assigning tests to Github issues and team members
describe('User Authentication', function () {
it('Issue 11 - can log in with valid credentials', function () {
// Test logic
})->todo(assignee: 'teammember1', issue: 11);
it('Issue 22 - rejects invalid credentials', function () {
// Test logic
})->todo(assignee: 'teammember2', issue: 22);
});
In this example, the test case 'Issue 11 - can log in with valid credentials' is assigned to 'teammember1', with a corresponding GitHub issue ID of 11.
When running your test suite, you can filter by the assignee or GitHub issue number, allowing you to focus only on the tests related to specific tasks or team members. For example, you can focus on tests assigned to Taylor Otwell or filter by a specific issue ID and quickly get an overview of what's pending or completed. Here’s how it might look:
./vendor/bin/pest --todos --assignee=taylor # or --issue=123
Keeping track of which tests correspond to which tasks is quite a big challenge, especially in larger test suites. With this new feature in Laravel Pest 3, task management is integrated directly into the testing workflow. This provides several benefits:
Better Organization: You can immediately see who worked on each test and what specific issue it addresses, reducing the time spent searching through test files.
Improved Collaboration: For teams working on large projects, this feature helps assign responsibilities clearly. Each team member knows exactly what they’re responsible for, and tests can be filtered accordingly.
Context Preservation: If a test fails in the future, you won’t have to guess who wrote it or which feature it was tied to. Pest 3 keeps all that information accessible, saving time when debugging.
The task management feature makes it easier to collaborate across teams and ensures that context is never lost when tests are passed between developers or revisited weeks (or months) later.
The new version of Laravel Pest introduces Architectural Presets, which simplifies architectural testing by allowing you to apply predefined rules with just one line of code:
Arch::preset('php');
Instead of manually setting individual rules, these presets cover foundational architectural standards for any PHP project. Pest 3 also includes specialized presets, such as the security preset, which blocks insecure functions like md5 and eval, and a Laravel preset, ensuring controllers adhere to Laravel’s RESTful conventions.
Let’s list all new presets available in Pest 3
Arch::preset(php);
Arch::preset(security);
Arch::preset(laravel);
Arch::preset(strict);
Arch::preset(relaxed);
It’s worth mentioning that pest allows you to selectively ignore certain preset rules when needed. For example:
arch()->preset()->security()->ignoring('md5');
This will ignore md5 checking and not fail arch tests.
We all know how easy it is to miss functions dd() or ray() while reviewing code on GitHub. With Laravel Pest 3’s Architectural Presets, teams of any size can quickly catch code that doesn’t belong in the final codebase. For smaller teams or solo developers, these presets eliminate the need to create detailed rules from scratch, while larger teams benefit from simplified, consistent code structure and quality. Pest 3’s presets act like a built-in code quality assistant, ensuring your project is secure, efficient, and organized without requiring much manual effort.
You can even create your own presets to track specific architectural standards that your team follows, making Laravel Pest an essential tool for saving time and maintaining quality across the board.
Pest 3 brings in mutation testing, an incredibly helpful feature to boost the quality of your test suite.
There are many ways to write a test when testing a single feature. Sometimes, a test is written so precisely that a minor change in the code will make it fail. Other times, you could remove half of the code, and the test would still pass, indicating it does not truly cover the functionality.
With mutation testing, Laravel Pest automatically makes small changes (mutations) in your code, re-runs your tests, and flags spots where the tests don’t catch these changes. This helps you quickly spot areas that are under-tested or need better coverage.
Here’s a simple example to illustrate:
test('can login with correct credentials', function (User $user) {
postJson(route('sendEmailCode'), [
'email' => $user->email,
'recaptcha_token' => 'fake-token',
]);
$response = $this->postJson('/api/login', [
'email' => $user->email,
'auth_code' => config('auth.testing_email_verification_code'),
], $this->jsonRequestHeaders);
expect($response->getStatusCode())
->toBe(200);
assertAuthenticated();
})->with('user');
With mutation testing, Laravel Pest might remove or alter a line like this:
test('can login with correct credentials', function (User $user) {
postJson(route('sendEmailCode'), [
'email' => $user->email,
#For example pest will remove this line
]);
$response = $this->postJson('/api/login', [
#For example pest will remove this line
'auth_code' => config('auth.testing_email_verification_code'),
], $this->jsonRequestHeaders);
expect($response->getStatusCode())
->toBe(200);
assertAuthenticated();
})->with('user');
With these mutations, tests will eventually fail because of the modifications, which means the test quality is solid. But if your tests pass even after a key logic is removed, mutation testing flags that they’re not quite robust enough.
You can easily enable mutation testing in Pest 3 using the following command:
./vendor/bin/pest --mutate
Pest will introduce mutations and display the results of any gaps in your test suite:
Mutation failed: Method `updatePassword` mutation not detected
This gives you instant feedback on where your tests are weak and need additional assertions or logic.
This feature pushes your tests to catch every possible edge case, helping ensure your code is resilient, reliable, and ready for real-world use.
By the way, Laravel development is one of our specialties. If you’d like to explore the services we offer and how we can support your next Laravel project, head over to our dedicated page - we’d love to assist you.
We are a 200+ people agency and provide product design, software development, and creative growth marketing services to companies ranging from fresh startups to established enterprises. Our work has earned us 100+ international awards, partnerships with Laravel, Vue, Meta, and Google, and the title of Georgia’s agency of the year in 2019 and 2021.