Today we are excited to announce the release of Pest v0.3! In the past months, we spent a lot of time working on the new Expectation API, and a brand new PHPStorm plugin, and more. Additionally, we've prepared Pest internally for PHP 8.
Now, let's see in more detail the changes we've merged into this release:
Expectation API
When we first released Pest, we already had in mind where we wanted Pest to be: simple, minimal, and elegant in all parts of testing.
The expectation API in this new version v0.3 is, in our opinion, a simpler alternative to the existing assertions API. Let's see some examples:
it('has countries', function () {
$countries = Countries::all();
// Assertions API
$this->assertCount(2, $countries);
$this->assertEquals(['en', 'fr'], $countries);
// Expectations API
expect($countries)->toBe(['en', 'fr'])->toHaveCount(2);
});
In this first example, you can immediately see how simple is the expectations API: chained expectations, less code, and it feels like a natural sentence.
it('has users', function () {
$users = Users::all(); // ['nuno', 'owenvoke']
// Assertions API
$this->assertContains('nuno', $users);
$this->assertNotContains('alex', users);
// Expectations API
expect($users)->toContain('nuno')->not->toContain('alex');
});
not
modifierIn this example 2, you can see that the expectation API makes use of the not
modifier for creating inverse expectations.
test('first article', function () {
$article = $this->get('/articles')[0];
// Assertions API
$this->assertEquals('My title', $article->title);
$this->assertStringContainsString('My content', $article->content);
// Expectations API
expect($article->title)
->toBe('My title')
->and($article->content)
->toContain('My content');
});
Next, in this example 3, you can see that you can also chain assertions on different values, and also how the naming as being improved: assertStringContainsString
vs toContain
.
expect($lastSeen)->toBeEmpty();
expect($published)->toBeTrue();
expect($archived)->toBeFalse();
expect($age)->toBeGreaterThan(20);
expect($age)->toBeGreaterThanOrEqual(21);
expect($count)->toBeLessThan(3);
// And more!
Finally, in the example 4, are some examples of the methods you can use while creating expectations. Head over to our website to find more about the expectation API: pestphp.com/docs/expectations.
Also, I've made a demo of the Expectation API on Freek Van der Herten's stream:
Finally, also many thanks to Alessandro Senese, and Alex Martin, who have helped tons on this feature.
PHPStorm Plugin
This new release also introduces a brand new PHPStorm plugin. Thanks to the amazing work of Oliver Nybroe, and Adel.
The first stable version (v0.3.0) of the @pestphp plugin for @phpstorm has just been released and now available in the marketplace for easy download! 😍
— Oliver Nybroe (@OliverNybroe) August 5, 2020
You can read about the features in this version in the following link https://t.co/pF51rZDXIQ
This new plugin makes testing a breeze for PHPStorm users. Here are some of the highlights:
- Autocompletion
- Running tests on the UI
- Debugger support
- Line coverage support
- Test subject navigation
- And more!

We believe the PHPStorm plugin is the final piece of the puzzle to make Pest a compelling testing alternative in the PHP ecosystem. And again, massive thanks to Oliver Nybroe, and Adel on this one.
PHP 8
Preparing an existing codebase for PHP 8 is not an easy task. Luckily, Graham Campbell, decided to help us with this.
We hope you enjoy this new release! And remember, you can find the upgrade guide here: pestphp.com/docs/upgrade-guide. It takes 1-2 minutes to migrate from Pest v0.2.
Get involved
Remember: Pest is a community project, there are many opportunities to contribute to the whole Pest ecosystem.
- Explore the docs: pestphp.com »
- Follow us on Twitter: @pestphp »
- Join us on the Discord Server: discord.gg/bMAJv82 »