behat
Run Behavior-Driven Development (BDD) tests
TLDR
Initialize a new Behat project
Run all tests
Run all tests from the specified suite
Run tests with a specific output formatter
Run tests and output results to a file
List the definitions in your test suites
SYNOPSIS
behat [options] [paths]
Examples:
behat
behat features/user_registration.feature
behat --strict --format progress
PARAMETERS
--help
Displays help information for the command.
--version
Displays the Behat version.
--strict
Causes the command to fail if undefined or ambiguous steps are encountered.
--dry-run
Runs the command without actually executing step definitions, useful for seeing proposed output.
--format <format>
Specifies the output format (e.g., pretty, progress, json).
--profile <name>
Runs Behat with a specific configuration profile defined in behat.yml.
--init
Initializes a basic Behat directory structure (features/ and behat.yml).
[paths]
Optional paths to feature files or directories to run (e.g., features/user_auth.feature or features/).
DESCRIPTION
Behat is a PHP framework for Behavior-Driven Development (BDD), inspired by Cucumber. It allows developers and business stakeholders to collaboratively define software behavior in human-readable language, known as Gherkin syntax. These specifications are written in plain text .feature files, describing scenarios with Given/When/Then steps.
Behat translates these scenarios into executable tests by mapping Gherkin steps to PHP code, called step definitions. This approach promotes clear communication, ensures that the software meets user expectations, and serves as living documentation. It is commonly used for acceptance testing and end-to-end testing of PHP applications.
CAVEATS
Behat is not a standard, pre-installed Linux utility. It is a PHP-based framework typically installed within a PHP project using Composer. Therefore, it requires a functioning PHP environment and the Composer dependency manager to be available on the system. Its execution is usually project-specific, relying on configuration files like behat.yml and the presence of .feature files.
CONFIGURATION
Behat's behavior is highly configurable via the behat.yml (or behat.yml.dist) file located at the project root. This file specifies paths to features, step definitions, formatters, and profiles.
FEATURE FILES
Scenarios are written in Gherkin syntax within .feature files, typically located in a features/ directory. Each file describes a specific feature with one or more scenarios.
STEP DEFINITIONS
The logic that connects Gherkin steps to actual PHP code is contained in step definitions. These are PHP methods, often within context classes, that execute actions or assert states based on the scenario steps.
HISTORY
The concept of Behavior-Driven Development (BDD) emerged from Test-Driven Development (TDD) and Agile methodologies, emphasizing collaboration between developers, QA, and business analysts. The Gherkin language, used by Behat, was popularized by the Cucumber framework (originally in Ruby). Behat was created by Konstantin Kudryashov as a PHP implementation of BDD, bringing these powerful practices to the PHP ecosystem. It has evolved significantly since its initial release, becoming a widely adopted tool for acceptance testing in PHP.