Integrate PHPStorm, Behat, and Vagrant

Behat tests can be initiated right from PHPStorm, saving a lot of hassle, as well as simplifying access to tests for less technical users.  Behat v3.3 does come pre-installed via composer and is found at /usr/local/bin/behat.  If you wish to use your own version of Behat, you’ll need that path later.  At Bryn Mawr, we have behat as part of our repository, so we use that path instead of the default /usr/local/bin/behat one.

Here’s some things you’ll need to have before starting:

  • PHPStorm open and licensed
  • RV project up and running
  • Behat path in the vagrant box
  • Behat.yml path
  • A Behat feature to run

PHPStorm Setup (File->Settings)

  1. Press the button for Project Root and press OK
  2. Settings Changes (File-Settings)Editor > Code Style
    1. Click Manage and import PHPStorm-Drupal.xml from [Project]/buildFiles/configs folder
    2. Version Control
      1. Remove the Project Root folder, add public_html
  3. Build Execution & Deployment > Deployment
    1. Add a new connection > Local or mounted folder
    2. Set Project file folder to point to [Project]/public_html
    3. Set Web server URL to http://website.vbox.local
    4. Change Deployment path to “.” under the mapping tab
  4. Language and Frameworks > PHP
    1. Change PHP level to 5.3 (RV uses PHP 5.3 by default.  Change this if you decide to upgrade to a different version)
    2. Add CLI Interpreter
      1. Remote > Vagrant
      2. Change name to “Rampant Vagrant”
    3. Select the CLI interpreter to “Rampant Vagrant”
    4. Add a path mapping for [Project]/public_html to /vagrant/public_html
    5. Behat Configuration
      1. Click to add a new Behat instance
      2. Select “Rampant Vagrant”
      3. Set path to be the appropriate behat path
      4. Set default runner path to the path of your behat.yml file
  5. Close Settings

You should now be able to run behat tests in the vagrant box right from PHPStorm.

Happy Testing!

Author: Jeremy Gonyea

A minimalist lifestyle with lots of technology added for good measure.

Leave a Reply

Your email address will not be published. Required fields are marked *