Getting Started with Behat – The Behavioral Testing Framework for PHP – Setting up Behat



Getting Started with Behat – The Behavioral Testing Framework for PHP – Setting up Behat

0 0


behat-presentation


On Github lpeabody / behat-presentation

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

Add a behat directory outside your web root.

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

Add and configure composer.json.
{
  "require": {
    "drupal/drupal-extension": "~3.0"
  },
  "config": {
    "bin-dir": "bin/"
  },
  "autoload-dev": {
    "psr-4": {
      "Kripalu\\": "src/"
    }
  }
}
						
composer install! 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.
Getting Started with Behat The Behavioral Testing Framework for PHP