Getting Started with Behat

The Behavioral Testing Framework for PHP

Setting up Behat

To get Behat running we need to install Behat and then initialize it for our project.

Install Behat in the Project Directory

  1. Add a behat directory outside your web root.

    This will typically live outside the root by one level. (eg. ./docroot/../behat)

  2. Add and configure composer.json.
    
    {
      "require": {
        "drupal/drupal-extension": "~3.0"
      },
      "config": {
        "bin-dir": "bin/"
      },
      "autoload-dev": {
        "psr-4": {
          "Kripalu\\": "src/"
        }
      }
    }
    						
  3. composer install!
  4. bin/behat --init

Configure Behat

Kripalu behat.yml


default:
  suites:
    forms:
      contexts:
        - Kripalu\MinkExtendedContext
        - Kripalu\Suite\Forms\FormsContext
      paths:
        - %paths.base%/features/forms
  extensions:
    Behat\MinkExtension:
      goutte: ~
      selenium2:
        wd_host: "http://localhost:8643/wd/hub"
      base_url: http://kripalu.dev
      files_path: %paths.base%/files
    Drupal\DrupalExtension:
      blackbox: ~
      api_driver: 'drupal'
      drush:
        alias: 'local.kripalu'
      drupal:
        drupal_root: '/Users/les.peabody/Sites/kripalu/docroot'
							

Write Some Tests!

  • All tests go in *.feature files, inside your features directory.