Pest 3.0 Released: Mutation Testing and Other Great News

Team Management, Mutation Testing, improvements to Type Coverage, and much more.

9. Sep 2024
·

Pest PHP 3.0 just dropped, and it’s an awesome release, with no breaking changes. Just change the required version in your composer.json file, and you’re good to go. Let’s dive into some of the changes and additions.

Mutation Testing support

It can at times be hard to ensure your tests are actually good, they might be too lax or generous to mistakes. This, amongst other benefits, is where mutation testing comes in. It essentially manipulates your related source code and checks if your tests break in response, and if they don’t break it might be sign that the test isn’t doing what it’s supposed to. With Pest 3.0, it’s as simple as passing --mutate to the script, and it will execute mutation tests.

An example could be changing your return from an array with data to an empty array. If your test asserts that the array is not empty, the test should naturally fail, but if your test simply asserts that the array exists, then it might still pass, despite the logic of your code having drastically changed.

Combining Mutation Testing with Code Coverage is one of the best ways to feel more confidence in the coverage metrics and your code-base.

Arch Presets

Another great addition is architecture test presets, which ensures that your code doesn’t or does do certain things in certain ways. That could for example be ensuring “var_dump” is never called. In this release they have included 5 presets:

  • php: avoid die, var_dump and such.
  • security: avoid eval, md5 and more.
  • laravel: ensures code follows Laravel conventions.
  • strict: ensures strict types, usage of final keyword and such.
  • relaxed: opposite of strict

These can be a great entry point to starting with architecture testing.

Better Type Coverage

Pest Type Coverage now checks for missing types on constants. This will be a great improvement when tracking Type Coverage with OtterWise, since the numbers will report more accurately going forward.

Improved Configuration API

Instead of utilizing uses(), Pest 3.0 also now supports a new expressive syntax. See the below example:

// before
uses(TestCase::class)->in(__DIR__);

// after
pest()->extends(TestCase::class);

There are many such improvements to readability, and overall I imagine how this further cement Pest’s position as the most developer friendly testing framework for PHP.

Summary

With the new release we see great advancements to the DX (developer experience), lots of improvements in existing features and some incredible new ones. If you have yet to try Pest, now just might be the time. With Type Coverage, Code Coverage, Parallel testing, Mutation testing and much more, it is an amazing choice for new and existing code bases.

There is more to the 3.0 release of Pest, this post merely stands as a quick glance into things we find interesting. You can read the full announcement on the official PestPHP website, where they cover Team Management with version control, Arch testing improvements and much more.

Improve code quality today_

With OtterWise, you can track Code Coverage, test performance, contributor stats, code health, and much more.