07 November 2024
Tim
Using Ray with your Pest tests
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.
Understand and fix bugs faster
Ray is a desktop application that serves as the dedicated home for debugging output. Send, format and filter debug information from both local projects and remote servers.