Back to overview

Using Ray with your Pest tests

7 November 2024

Image of Tim

Tim

Writing and debugging tests are essential for many Laravel developers. Ray and Pest work brilliantly together to provide a streamlined debugging and testing experience. Ray is great for real-time feedback on code execution, while Pest, known for its clean and expressive syntax, simplifies writing and running tests. Together, they bring clarity and efficiency to writing tests in Laravel.

Open a new window when running tests

When running Pest tests, opening a new Ray window lets you keep test output separate from other Ray debugging data. This approach is especially helpful if you're actively developing while testing, as it keeps test debugging clear and distinct.

You can use Ray's newScreen() method to open a new Ray window. Here's how to apply it in your Pest test setup (Pest.php):

uses()->beforeEach(function () {
	ray()->newScreen('Tests');
});

This command opens a fresh Ray window each time a test run begins, letting you focus on output from your Pest tests without mixing in any debugging data from your main app logic.

Using Pest's Ray method

Pest has a Ray method that you can call on any expectation so you can inspect them.

expect($value)->ray(); // Sends $value to Ray for inspection

Checking for Ray statements

Most of the time, you don't want to ship code that still has Ray calls in it. One easy way to avoid this is to leverage Pest's architecture tests.

Using the PHP preset Pest will show a failing test each time it detects a Ray statement still in your code.

To enable this preset, you simply have to add the following code to your Pest.php file:

arch()->preset()->php();

This is only one possible way to prevent Ray calls from slipping into your production code. You can also check our blogpost on how to automatically remove calls with Rector.

Stay in the loop with updates & promotions for Ray

We only send a few emails a year.

Debug without breaking your flow

Ray keeps all your debug output neatly organized in a dedicated desktop app.

Licenses are valid for 1 year and managed through Spatie. Licenses purchased before Ray 3 remain valid. VAT is calculated at checkout.