How to run Pest tests along PHPstorm and Laravel Sail
by Vladimir Nikolic, CEO Coding Wisely
I am thrilled to be using Pest for PHP testing! The syntax is incredibly readable and expressive, which makes writing and maintaining tests a joy. I love how Pest's conversational style feels more like a natural language than a coding language, making it so easy to understand what each test is doing. The additional features, such as test parallelization and coverage reports, are a huge bonus that help me to be more productive and confident in my work. Overall, Pest has transformed my testing experience and made me a very happy developer!
This article documents the process of using Laravel Sail for local development, and provides instructions on configuring PhpStorm to work smoothly with Sail and tests with Pest.
With every project i struggle to remember what has to be done, so decided to put it in article.
To install the Pest plugin in PhpStorm, follow these steps:
Open PhpStorm and go to the "Settings/Preferences" menu by clicking on the gear icon in the bottom left corner of the window.
In the settings menu, select "Plugins" from the left-hand sidebar.
In the Plugins menu, click the "Marketplace" tab at the top of the window.
Search for "Pest" in the search bar at the top of the window.
Click the "Install" button next to the Pest plugin.
Once the installation is complete, click the "Restart IDE" button to restart PhpStorm and activate the Pest plugin.
After restarting PhpStorm, you can start using Pest in your PHP projects.
Note: Pest requires PHP 7.4 or later, so make sure you have the appropriate version installed before using the plugin.
Sail is a tool that enables the use of Docker without having to deal with Docker commands directly. It relies on an image that includes the latest versions of PHP, Nginx, and MySQL. Sail is a Laravel package, which means it can be used with either a new Laravel installation or an existing project.
To use Sail, you need to have Docker installed on your machine. If you don't already have it, you can download it from https://www.docker.com/. You also need to have PHP installed to run Composer and install Sail on existing projects.
To configure PhpStorm to use Docker, open the settings and select "PHP" -> "Test Frameworks." Click the plus sign to add a remote connection and select the Sail container, then select "Docker" and the Sail image. This tells PhpStorm to use Docker for CLI actions.
Next, make sure that proper test framework is selected:
Type in your terminal: ```docker network ls```
Remember the network:
Click on folder icon to pop next window and enter the network mode, in my case agri4all_sail.
That should do it, right click on file and select run test, and you will get results:
or run only one method with right click directly in file.
Vladimir, with over 25 years in the software industry, serves as the CEO of Coding Wisely.
The information provided in this article is based on the author's knowledge and experience as of the publication date. Technology and tools may have evolved since then. Always refer to the official documentation for the latest instructions and updates.