PEST v0.3 is now released!

PEST v0.3 is now released!

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.

pestphp/pest
Pest is an elegant PHP Testing Framework with a focus on simplicity - pestphp/pest

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);
});
Example 1 - multiple expectations

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');
});
Example 2 - not modifier

In 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');
});
Example 3 - multiple expectations, but on different values

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!
Example 4 - multiple expections methods

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.

pestphp/pest-intellij
The official Pest Plugin for PhpStorm / IntelliJ IDEA - pestphp/pest-intellij

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!
example 5 - autocompletion on test closures

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.

feat: adds support to phpunit 9.3 and php 8.0 by GrahamCampbell · Pull Request #128 · pestphp/pest
Q A Bug fix? yes New feature? yes Fixed tickets #127 This PR: Drops support for PHPUnit less than 9.3 Adds support for PHP 8.0 Note that PHP 8.0.0-beta1 will be released on Aug 06 2020...

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.

Show Comments