Fork us

Behat Documentation

Behat v2.x is not maintained anymore. Please upgrade to v3.x ASAP

Behat is an open source behavior-driven development framework for PHP 5.3 and 5.4. What is behavior-driven development, you ask? It’s the idea that you start by writing human-readable sentences that describe a feature of your application and how it should work, and only then implement this behavior in software.

For example, imagine you’re about to create the famous UNIX ls command. Before you begin, you describe how the feature should work:

Feature: ls
  In order to see the directory structure
  As a UNIX user
  I need to be able to list the current directory's contents

    Given I am in a directory "test"
    And I have a file named "foo"
    And I have a file named "bar"
    When I run "ls"
    Then I should get:

As a developer, your work is done as soon as you’ve made the ls command behave as described in the Scenario.

Now, wouldn’t it be cool if something could read this sentence and use it to actually run a test against the ls command? Hey, that’s exactly what Behat does! As you’ll see, Behat is easy to learn, quick to use, and will put the fun back into your testing.


Behat was inspired by Ruby’s Cucumber project, especially its syntax (called Gherkin).

Useful Resources

Other useful resources for learning/using Behat:

More about Behavior Driven Development

Once you’re up and running with Behat, you can learn more about behavior-driven development via the following links. Though both tutorials are specific to Cucumber, Behat shares a lot with Cucumber and the philosophies are one and the same.