This feature is supported in the Ultimate edition only.
The following is only valid when PHP Plugin is installed and enabled!
With IntelliJ IDEA, you can praactice behaviour-driven development by running scenarios using the Behat framework.
Currently IntelliJ IDEA supports integration with Behat 3
and Behat 2
versions.
Native support of Behat in IntelliJ IDEA includes:
-
Recognition of and coding assistance for
.featurescenario files and.phpscenario definition files. -
Support of Gherkin
syntax in .featurefiles: Feature, Scenario, Given, When, Then, And, and But keywords. - Recognition of @given, @when, and @then annotations in definition files.
-
Setting correspondence between scenarios and their definitions through regular expressions
in accordance with the PCRE
standard for Behat 2.4 and PCRE+ for Behat 3.0.
Turnip expressions
are also welcome.
On this page:
- Before you start
- Downloading and installing Behat
- Configuring the Behat installation in IntelliJ IDEA
- Creating a run configuration of the type Behat
- Launching Tests
Before you start
- Make sure the PHP interpreter is configured in IntelliJ IDEA on the PHP page, as described in Configuring Local PHP Interpreters and Configuring Remote PHP Interpreters.
- Make sure the PHP and Behat plugins are installed and enabled. The plugins are not bundled with IntelliJ IDEA, but they can be installed from the JetBrains plugin repository as described in Installing, Updating and Uninstalling Repository Plugins and Enabling and Disabling Plugins. Once enabled, the plugins are available at the IDE level, that is, you can use them in all your IntelliJ IDEA projects.
- Configure the PHP interpreter to use Behat with, as described Configuring Remote PHP Interpreters. Note that Behat 3 requires PHP 5.5 and higher.
Downloading and installing Behat
You can acquire Behat in the following ways:
-
Download the
behat.phararchive. - Use the Composer dependency manager.
Downloading the behat.phar archive
-
Download
behat.pharat the Behat Downloads page
.
-
Store
behat.pharon your computer:-
To get full coding assistance in addition to simply running Behat scenarios,
store
behat.pharunder the root of the project where Behat will be later used. In this case, IntelliJ IDEA will include it in indexing, so references to Behat classes will be successfully resolved and you will be able not only to run scenarios but also provided with full coding assistance. -
If you only need to run Behat scenarios and you do not need any coding assistance, you can save
behat.pharoutside the project. In this case, IntelliJ IDEA will only run Behat scenarios without providing coding assistance.
-
To get full coding assistance in addition to simply running Behat scenarios,
store
Installing Behat using the Composer dependency manager
Before you start, make sure Composer is installed on your machine and initialized in the current project, see Using Composer Dependency Manager.
- On the main menu, choose .
-
In the Add Composer Dependency dialog that opens, select the
behat/behatpackage from the Available Packages list, possibly using the search field. The list shows all the available packages, however, the packages that have been already installed are marked with a tick.Choose the relevant version from the Version to install drop-down list.
-
If necessary, expand the Settings hidden area and specify the advanced installation options.
In the Command line parameters text box,
type the additional command line parameters to adjust the add dependency procedure.
For example, to have the package added to the
require-devsection instead of the defaultrequiresection type-dev. For more information about Composer command line options during installation, see https://getcomposer.org/doc/03-cli.md
.
- Click Install.
When you click Finish, the create-project command is invoked with the selected package.
This results in creating a Composer project whose configuration and structure depends on the selected package,
see https://getcomposer.org/doc/03-cli.md#create-project for details.
After that a IntelliJ IDEA project opens.
Configuring the Behat installation in IntelliJ IDEA
- Open the Settings / Preferences Dialog by pressing ⌘,⌘,⌘,⌥ F7^ ⌥ S or by choosing for Windows and Linux or for macOS. Expand the Languages & Frameworks node, and then click Behat under PHP.
-
On the Behat that opens, specify the location of the Behat executable file or
behat.phararchive and the PHP interpreter to use Behat with. This PHP interpreter can be installed either locally, or in a Vagrant virtual environment, or on a remote host, or in a Docker container. For information on configuring PHP interpreters, see Configuring Local PHP Interpreters and Configuring Remote PHP Interpreters.The central pane of the page shows a list of configured PHP interpreters that are associated with Behat installations. The list contains at least one item (Local) which cannot be removed. The contents of the right-hand pane depend on the type of the selected interpreter. To use Behat with a local PHP interpreter:
- Choose Local.
-
In the Behat Library area, specify the location of the Behat executable file or
behat.phararchive. -
Click
next to the Path to Behat directory or phar file text box. IntelliJ IDEA detects the version of Behat
and displays it below the text box.
To use Behat with a remote PHP interpreter, click the Add toolbar button
in the central pane and do one of the following depending on your workflow:
-
To use Behat in a Vagrant environment:
-
In the Behat by Remote Interpreter dialog box,
choose the desired PHP interpreter configuration in a Vagrant environment.
When you click OK, IntelliJ IDEA returns to the Behat page.
IntelliJ IDEA displays the appointed PHP interpreter configuration in the CLI Interpreter field. The field is read-only, to update the chosen interpreter configuration or create a new one, click the
whereupon IntelliJ IDEA brings you to the Interpreters dialog box.
-
In the Behat Library area, specify the location of the Behat executable file or
behat.phararchive in the target Vagrant virtual environment. For example, if you installed Behat through the Composer dependency manager, the location isvendor/bin/behat. -
Click
next to the Path to Behat directory or phar file text box. IntelliJ IDEA detects the version of Behat
and displays it below the text box.
-
In the Behat by Remote Interpreter dialog box,
choose the desired PHP interpreter configuration in a Vagrant environment.
When you click OK, IntelliJ IDEA returns to the Behat page.
-
To use Behat on a remote host with SSH access:
-
In the Behat by Remote Interpreter dialog box,
choose the desired PHP interpreter configuration on a remote host.
When you click OK, IntelliJ IDEA returns to the Behat page.
IntelliJ IDEA displays the appointed PHP interpreter configuration in the CLI Interpreter field. The field is read-only, to update the chosen interpreter configuration or create a new one, click the
whereupon IntelliJ IDEA brings you to the Interpreters dialog box.
-
In the Behat Library area, specify the location of the Behat executable file or
behat.phararchive on the target host. -
Click
next to the Path to Behat directory or phar file text box. IntelliJ IDEA detects the version of Behat
and displays it below the text box.
-
In the Behat by Remote Interpreter dialog box,
choose the desired PHP interpreter configuration on a remote host.
When you click OK, IntelliJ IDEA returns to the Behat page.
-
To use Behat in a Docker container:
-
In the Behat by Remote Interpreter dialog box,
choose the desired PHP interpreter configuration in a Docker container.
When you click OK, IntelliJ IDEA returns to the Behat page.
IntelliJ IDEA displays the appointed PHP interpreter configuration in the CLI Interpreter field. The field is read-only, to update the chosen interpreter configuration or create a new one, click the
whereupon IntelliJ IDEA brings you to the Interpreters dialog box.
-
In the Behat Library area, specify the location of the Behat executable file or
behat.phararchive on the target host. -
Click
next to the Path to Behat directory or phar file text box. IntelliJ IDEA detects the version of Behat
and displays it below the text box.
-
In the Behat by Remote Interpreter dialog box,
choose the desired PHP interpreter configuration in a Docker container.
When you click OK, IntelliJ IDEA returns to the Behat page.
-
In the Test Runner area,
appoint the configuration
.ymlfile to use for launching and executing scenarios.By default, Behat looks for a
behat.ymlconfiguration file in the project root folder or in theconfigfolder. You can appoint a custom configuration file.-
Clear the Default configuration file check box
to have Behat use the
behat.ymlconfiguration file from the project root folder or from theconfigfolder. If no such file is found, test execution fails, therefore it may be more reliable to specify the configuration file explicitly. -
Select the Default configuration file check box
to specify your own
.ymlconfiguration file. This file will be later used as default in all Behat run/debug configurations.In the text box, specify the location of the configuration file to use. Type the path manually or click the
button and choose the file in the dialog box that opens.
-
Clear the Default configuration file check box
to have Behat use the
Creating a run configuration of the type Behat
- Choose on the main menu
-
In the Edit Configuration dialog box that opens, click the Add New Configuration toolbar button
,
and choose Behat on the context menu.
- In the Run/Debug Configuration: Behat dialog box, specify the scenarios to run and customize the behavior of the current PHP interpreter by specifying the options and arguments to be passed to the PHP executable file.
Launching Tests
For information about writing Behat features,
see http://docs.behat.org/en/latest/user_guide/writing_scenarios.html
.
To run or debug your tests, do one of the following:
- On the main menu, choose and monitor test results in the Run tool window as described in Viewing and Exploring Test Results.
- On the main menu, choose and debug the tests in the Debug tool window.