Behat Documentation

Behat is an open source Behavior Driven Development framework for PHP 5.3+.What’sbehavior driven development, you ask? It’s a way to develop softwarethrough a constant communication with stakeholders in form of examples;examples of how this software should help them, and you, to achieve your goals.

For example, imagine you’re about to create the famous UNIXls command.Before you begin, you will have a conversation with your stakeholders (UNIXusers) and they might say that even though they like UNIX a lot, they need away to see all the files in the current working directory. You then havea back-and-forth chat with them about how they see this featureworking and you come up with your first scenario (an alternative name for examplein BDD methodology):

Feature: Listing command  In order to change the structure of the folder I am currently in  As a UNIX user  I need to be able to see the currently available files and folders thereScenario: Listing two files in a directory    GivenI am in a directory "test"AndI have a file named "foo"AndI have a file named "bar"WhenI run "ls"ThenI should get:"""      bar      foo"""

If you are a stakeholder, this is your proof that developers understandexactly how you want this feature to work. If you are a developer, this is yourproof that the stakeholder expects you to implement this feature exactly in theway you’re planning to implement it.

So, as a developer your work is done as soon as you’ve made thelscommand, and made it behave as described in the “Listing command” scenario.

You’ve probably heard about this modern development practice called TDD, whereyou write tests for your code before, not after, the code. Well, BDD is likethat, except that you don’t need to come up with a test - yourscenarios areyour tests. That’s exactly what Behat does! As you’ll see, Behat is easy tolearn, quick to use, and will put the fun back into your testing.

Behaviour Driven Development

Once you’re up and running with Behat, you can learn more about behaviourdriven development via the following links. Though both tutorials are specificto Cucumber, Behat shares a lot with Cucumber and the philosophies are oneand the same.

Note

Behat was heavily inspired by Ruby’sCucumber project. Since v3.0,Behat is considered an official Cucumber implementation in PHP and is partof one big family of BDD tools.

Documentation Contents