How to integrate Behat with PHPStorm / other IDE
Asked Answered
C

1

11

Behat is the leading BDD framework for PHP. I use PHPStorm and want to integrate Behat into the IDE as an external tool.

Question: How should I set up Behat as an external tool (ie, output filters, macros, etc) in PHPStorm or any other IDE for that matter?

note: PHPUnit has deprecated their BDD support and will remove it in 3.6 (in deference to Behat), so I believe the integrated PHPUnit testing in PHPStorm isn't ideal for Behavior Driven Development.

update Feb 8-2012: PHPStorm's roadmap indicates Behat syntax will be integrated in the 4.0 release which is due Q1 2012! What can I say - PHPStorm rocks.

Cauterant answered 10/3, 2011 at 6:27 Comment(0)
C
4

Here's what I came up with, if anybody else out there needs it.

First, create behat-html.bat in the same folder as behat.bat (your PHP folder). The contents of behat-html.bat should look something like this:

call %PHP_PEAR_BIN_DIR%\behat.bat --out="features\support\behat_test_output.html" --colors --format="html" %*
call features\support\behat_test_output.html

Second, in PHPStorm setup the external tool to run Behat with whatever parameters you like (tags, scenarios, etc). Here are my settings for a general-purpose command:

Program: C:\Progz\wamp\bin\php\php5.3.5\behat-html.bat
Parameters: $FilePath$
Working Directory: $FileDir$\..

Third, setup a Keymap to run the tool.

Now with your .feature file in focus, press your shortcut key. The batch file will run the scenarios, generate a pretty HTML output file, and open that file with your default browser. Not as nice as having it integrated into PHPStorm, but it's a pretty efficient work flow nevertheless.

Tip: You might also want to set up a second external-tool in order to run with --strict

Hope this helps!

Cauterant answered 10/3, 2011 at 21:28 Comment(4)
How did you set up the formatting? BTW, the screenshot link does not work anymore.Loy
In order to setup formatting, go into Settings|File Types and add a new file type. Give it a name and a description, and you should see a series of form inputs that allow you to define how comments are denoted, and up to 4 different types of 'Keyword'. You can then assign syntax colouring to these keywords by going into Settings|Editor|Colors & Fonts|Custom and you should see the appropriate syntax options (Keyword 1 is the colour for keywords you added in the first tab of your new file type, for example). Hope this helps!Prosecute
@FireCoding : too bad, if you have a ' in your feature description, it's interpreted as a string. This char is widely used in French. Do you know a way to limit the string detection to the " char ?Paraformaldehyde
@ClementHerreman : I'm not 100% sure, but I believe this is built deep into the core of the IDE and its parsing algorithm... I cannot imagine that this is changeable, but you'd better ask JetBrains. Let us know if you find a solution.Cauterant

© 2022 - 2024 — McMap. All rights reserved.