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.
Subscribe to Blog updates
Thanks, we've got you!
Laravel Best Practices: How to Automate Your Routine
5 useful tips to make your experience with the Laravel framework more productive
HTTP Client in PhpStorm Overview
When developing a web service, you would usually test it by sending all kinds of HTTP requests to it and examining what’s returned. In PhpStorm, you can do this directly in the code editor. In this post, we’ll use the github.com/JetBrains/phpstorm-http-client-tutorial example project to demonstra…
Quickstart with Docker in PhpStorm
So, you’ve decided to try something new today and started a project from scratch. Your first step will be to set up a development environment: at the bare minimum, you’d want to run a web server and a PHP interpreter (preferably – with the debugging engine installed). With Docker, you can star…
Install PhpStorm with Snaps
Exciting news for Linux users: you can now use snaps to install PhpStorm builds. Snaps will update your app automatically, and you’ll always have a fresh PhpStorm build right out of the oven. Snaps are really easy to install and use. On Ubuntu 16.04 LTS or later, snaps come pre-installed. On other L…