Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Next »

Behat is a BDD (behavior driven development) framework for PHP. With BDD, you write human-readable stories that describe the behavior of your application. These stories can then be auto-tested against your application. This tutorial describes how to install, configure and use Behat right from the PhpStorm IDE.

Behat support is currently available in PhpStorm 8 EAP.

Error rendering macro 'toc' : [com.ctc.wstx.exc.WstxLazyException] com.ctc.wstx.exc.WstxParsingException: Undeclared namespace prefix "fb" at [row,col {unknown-source}]: [3,372]

Prerequisites

To make use of Behat, we first have to install it on our system. Read more about Behat installation in official documentation.

Installing Behat via Composer

A Composer package for Behat is available. A dependency can be added to composer.json using Composer Support in PhpStorm (recommended) or manually.

Use the Composer | Add dependency... context menu on your project and install behat/behat package:

Installing Behat with Phar package

You can either download behat.phar package from Behat GitHub repository, or install it in Settings | PHP | Behat | Download behat.phar from...

Run Configuration for Behat

Behat run configurations can be set in the same way as PHPUnit’s. Usual testing workflow (running with Run action, UI for running tests and displaying results) is supported.

Setting Behat run configuration via Edit Configurations... action

1. New Run Configuration for Behat can be created either in Run | Edit configurations... menu, or with the same action from the toolbar:


2. Add a new configuration with   button and select Behat

3. Provide path to the directory which contains test scenarios (/Users/user/PhpStormProjects/Behat/features in our case). Test scope can be defined as a Directory, File, Scenario or Defined in configuration file. There are many additional options which can be configured in this dialog (such as alternative Behat configuration file, test runner options, command line options, actions to be performed before launch).

4. If you haven't configured path to Behat directory or behat.phar file before, PhpStorm will offer you to do so with a Fix button in the run configuration dialog. Provide path to Behat and default configuration file (if needed).

Behat configuration can be always changes in Settings | PHP | Behat.

Alternatively you can use Behat via Remote Interpreter, configuration is similar with the only difference that you should have remote PHP interpreter configured.

Setting Behat run configuration via file/folder context action

Apart from standard workflow which involves providing paths to test scenarios manually, you can invoke context action Create Run Configuration | Folder name (with Behat icon) _or create and run it straight away with _Run | Folder name (with Behat icon) for folders in Project Tool Window:

Same actions are available in Run | Run menu (Alt + Shift + F10 / Ctrl - Alt - R):

It works in the same way for context action inside *.feature file in the editor (creating run configuration or running all scenarios from file or single scenario from file):

Running Behat tests and evaluating results

As stated earlier, usual testing workflow (running with Run action, UI for running tests and displaying results) is supported similar to the one for PHPUnit.

That means that as soon as the run configuration is created (or you are running test scenarios for folder/file from the context menu action), your tests will be run and the results will be displayed in the test runner tab:

From the test runner tab you can navigate to source of the test, or sort/filter/etc results of tests.

Behat Intellisense

Resolve from step in Gherkin file to Context file

Find Usages from Context file to usages in Gherkin files

Keyword and step completion

Generation for undefined steps

  • No labels