Support for Behat

By Jérôme Vieilledent, on Mar 03, 2021

If you are familiar with functional and/or Behavior Driven Development (BDD), you may already have heard of Behat, the PHP framework of reference when it comes to behavior tests. It allows to write scenarios using a structured natural language and is perfectly adapted to the web environment.

In the context of automated testing, Blackfire provides a Builds system that you can use to automate your performance tests. By default, it is based on the Blackfire Player. The Player has its own DSL, somewhat similar to Behat’s. While it is often easy to use, it can be a pain to maintain two parallel test suites if you are a Behat user.

Brace Yourselves, Behat Integration Has Come

Therefore, I am really happy to announce that Behat integration is now ready 🙌! It is part of the PHP SDK, as of version 1.25.0.

This integration gives you the ability to create Blackfire Builds and Scenarios using Behat, without changing anything in your feature or context files. It exposes a Behat extension and a dedicated Mink driver.

Install and Configure

First, you need to add the Blackfire PHP SDK as a dependency in your project, together with Mink and the BrowserKit driver:

composer require blackfire/php-sdk friends-of-behat/mink-extension friends-of-behat/mink-browserkit-driver

Second, configure Behat via you behat.yaml file:

default:
    extensions:
        # Declare and configure the BlackfireExtension
        Blackfire\Bridge\Behat\BlackfireExtension:
            # UUID or name of your Blackfire environment
            blackfire_environment: 'My Blackfire environment'
            # The name you want to give to your Blackfire Builds triggered by Behat
            build_name: 'BDD test with Behat'
        Behat\MinkExtension:
            base_url: 'https://localhost:8000'
            sessions:
                default:
                    # Declare the Blackfire Mink driver
                    blackfire: ~

    suites:
        'Main Suite':
            contexts:
                - FeatureContext
                - Behat\MinkExtension\Context\MinkContext

With this config, a Blackfire Build will be created for each configured test suite. Mink will use the Blackfire driver as the default one, which will create a profile for each step of each scenario.

Please note that you may control which HTTP requests are being profiled within your feature context classes.

Start your Premium Trial Now!

Builds are available for Premium and Enterprise plans. What about giving it a try for free? 15 days evaluation and no credit card required!

Happy Profiling!

Jérôme Vieilledent

As a Developer Advocate, Jérôme is all about spreading the love! His technical/development background enable him to talk as a peer to peers with our developer users. You’ll read his tips and advices on performance management with Blackfire. And he’ll support you as a day-to-day user.