Support for Laravel Tests

By Thomas di Luccio, on Jan 07, 2022

Laravel comes with built-in testing capabilities based on PHPUnit. The Frameworks extends PHPUnit adding convenient helper methods to write functional and integration tests.

Adding Performance Tests for the critical user journeys is key to ensuring the best user experience possible and quality of the service. Having Unit, Functional, and Performance tests in one place could improve the Developer Experience of Laravel Applications makers.

New Integration with Laravel

We are thrilled to announce the support for Laravel Tests. Performance Tests can now be integrated into the existing test cases of Laravel applications.

This Integration relies on the PHP SDK (1.28+ version) and symfony/http-client to perform real HTTP requests within the testing environment. Extending the BlackfireTestCase will activate the feature with the possibility to fine-tune what will be profiled. Laravel tests functions names and signatures remain identical.

namespace Tests\Feature;

use Blackfire\Bridge\Laravel\BlackfireTestCase;

class LoveThisTest extends BlackfireTestCase
{
    // Give a title to the scenario.
    protected $blackfireScenarioTitle = 'Name of this scenario';

    public function test_get(): void
    {
        $response = $this->get('/foo');

        $response->assertStatus(200);
    }

    public function test_without_profiling(): void
    {
        $response = $this
            ->disableProfiling()
            ->get('/bar');

        $response->assertStatus(200);
    }

    public function test_command(): void
    {
        $this
            ->artisan('foo:bar -my -args')
            ->assertExitCode(0);
        ;
    }
}

Laravel’s default HTTP and Artisan test functionalities are extended in order to have the assertions defined within the .blackfire.yaml file evaluated when triggering profiles of HTTP requests of Artisan commands from the test cases.

When running your tests, a Blackfire Build is automatically started, and a Scenario is created for each instance of BlackfireTestCase.

Check the documentation to learn more about the Integration with Laravel Tests and integrate those with your Continuous Observability Strategy.

Subscribe to Blackfire Monitoring

Start a Blackfire Monitoring subscription today and set up the Continous Observability of your Laravel applications.

Happy Performance Optimization!

Thomas di Luccio

Thomas is a Developer Relations Engineer at Platform.sh for Blackfire.io. He likes nothing more than understanding the users' needs and helping them find practical and empowering solutions. He’ll support you as a day-to-day user.