Behat

A behavior-driven development (BDD) testing framework for PHP driven by Gherkin.

Tool
Composer
vv4.0.0-alpha1
3,968stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
72/100Good
Development Activity48
Maintenance52
Community88
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
81/100Excellent
Architecture88
Code Quality88
Innovation78
Learning Curve68

Behat is a behavior-driven development (BDD) framework for PHP that lets teams describe application behavior in plain, human-readable Gherkin scenarios and then execute those scenarios as automated tests. Business stakeholders, testers, and developers share the same .feature files, and Behat maps each step to PHP step-definition methods in context classes.

Run from the command line via vendor/bin/behat, it discovers features, matches steps against your definitions, and reports which expectations pass or fail. Behat is heavily extensible through its Symfony-based service container, supports hooks, suites, profiles, and translations, and integrates with tools like Mink for web acceptance testing — making it the de facto standard for StoryBDD in the PHP ecosystem.

What You Get

  • A CLI test runner (vendor/bin/behat) that discovers and executes Gherkin .feature scenarios
  • Step definitions and context classes that map plain-language steps to PHP code
  • Hooks, suites, and profiles for organizing and configuring test runs
  • An extensible, Symfony-based architecture with extensions like Mink for web acceptance testing

Common Use Cases

  • Writing acceptance tests as shared Gherkin scenarios between business and developers
  • Driving end-to-end web tests through Mink and a browser or HTTP driver
  • Documenting and verifying business rules as executable specifications

Under The Hood

Architecture — Behat is built around a Symfony service container assembled from extensions. The Gherkin package parses feature files into an AST; Behat’s Tester, Definition, Hook, and Context services (under src/Behat/) then match each scenario step to a step-definition method, invoke it, and collect results, which output formatters render. The bin/behat entry point boots the container from your behat.dist.php/behat.yml configuration and CLI options.

Tech Stack — Written in PHP on top of Symfony components (Console, DependencyInjection, EventDispatcher, Config) and the behat/gherkin parser. It is distributed via Composer and packaged as a PHAR through box.

Code Quality — The repository has an extensive tests/ suite plus a large features/ directory where Behat tests itself with its own Gherkin scenarios (dogfooding), and it enforces static analysis with PHPStan and refactoring rules via Rector — signaling a mature, well-maintained codebase.

API Design — Authors write natural-language Gherkin and annotate PHP context methods with step patterns, so the ‘API’ is largely declarative. Configuration through profiles and suites is flexible, and the extension system lets the tool grow (Mink, custom formatters) without changing test code.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search