How the Pest PhpStorm Plugin Will Improve Your Testing Workflow
Perhaps you’ve already heard of Pest. It is a new PHP testing framework with a focus on simplicity. The Pest PhpStorm plugin is a new addition to PhpStorm’s growing ecosystem. With this plugin, testing your code in your favorite IDE is even simpler and faster!
The source code behind the plugin is open source and community-driven, just like Pest itself.
You can find the plugin in the JetBrains Marketplace, a platform for plugin vendors to deliver tools like Pest to a wider audience and quickly roll out updates for everyone. Just search for “Pest” and install it from there.
Just like PHPUnit test, you can run your PEST test directly from PhpStorm. When you place your caret inside a test and trigger the run window, a run configuration will be created for that specific test. You can place the caret outside any particular test but still in the file to trigger all the tests in that file.
After pressing run, your new run configuration is available and can be edited. Now you can change your test or simply run the current configuration by pressing Ctrl+R (Shift+F10 on Windows)
A run configuration can also be created by clicking the PEST styled run icon that is in the gutter on the line with the test.
Pest lets you write assertions by calling functions or methods on
$this. The plugin supports autocompletion, so you can see what assertions are available as you type!
Pest can run some code before each test. In that code, you can assign a value to a property that will be available in the tests themselves.
This is very useful if you need to share some data across multiple tests. And again, the plugin can autocomplete the properties that are defined.
Debugging code is often necessary. Fortunately, Pest works well with Xdebug. The plugin allows you to run a test with the debugger. You will be able to see all of the debugging information directly in PhpStorm, and breakpoints can be easily added.
Pest also supports code coverage. This means that we can see how much of our code is covered by our Pest tests and easily pinpoint where we need to add more tests. The plugin has support for code coverage, and the code coverage results can also be seen directly in PhpStorm.
Running together with PHPUnit
PHPUnit and Pest tests can be run together. This allows existing PHPUnit users to switch easily to Pest, as they won’t have to convert all of their old tests but can instead transition on an as-needed basis. The plugin also follows the principle that you should be able to run two testing frameworks together as if they are one.
We hope this post sheds some light on what Pest and its plugin for PhpStorm can do for you. If you want to stay informed about Pest, take a quick look at the documentation to learn more, join the other users on the official Discord server, and follow Pest on Twitter.
Thanks for reading!
Laravel backend developer at Worksome.