Fallback Image
Fallback Image

Testing With

Laravel PEST

In the Laravel DACH Meetup in October, our speaker Alexander focused on Laravel PEST. Here is a summary.

At our Meetup in October, it was all about testing. Our PHP developer Alexander dealt intensively with Laravel PEST and provided some interesting facts about testing in general as well as insights into a concrete project.

Why Is Testing Worth It?

PEST is a PHP testing framework for Laravel. But why is testing so important? On average, a developer creates up to 70 bugs per 1,000 lines of code (source: Coralogix 2015). Of these, 15 eventually find their way to the customer. Fixing bugs takes up to 30 times longer than writing code. Most developers will know this from their everyday lives. It is therefore not surprising that developers spend about 75% of their time fixing these bugs, losing 1,500 hours a year and a corresponding budget of 113 billion in the US alone. This can be counteracted by testing.

Other advantages of testing are higher quality and easier maintainability of code. In addition, code can be documented and it is easier for new developers to get started with projects. The similarity of PEST to widely used frontend testing frameworks such as Jest also makes testing easier, especially for beginners. In addition, boilerplate code is reduced, which makes the tests clearer.

Despite all these advantages, testing is unfortunately often neglected in practice, as it makes development more time-consuming and requires a certain amount of experience.

PEST in Action

PEST was developed by Nuno Maduro - Laravel Core developer - to make testing easier and more integrable into everyday life.

Everything is simply integrated into a project via a composer require command. For Laravel, the Laravel plugin for PEST should also be installed, which enables access to the Laravel-specific test API. While in PHPUnit tests are written in classes, in PEST functions are used. These accept two arguments. A string describing the test and a closure with the actual test logic.

Tests with PEST can usually be divided into three phases:

  1. Prepare phase: everything necessary for the test is collected.
  2. Execution: The code to be tested is executed.
  3. Assertion: Does what was expected happen?

To execute the tests, the ./vendor/bin/pest command or in Laravel - php artisan test is used.

The recording of the entire Meetup, including an example project, is available in the video.

Fallback Image

Further Useful Information and Sources on PEST

Would you also like to be a

speaker at our Meetup?

Contact us!