Behavior-Driven Development (BDD) is an Agile approach that mixes requirement gathering, documentation and acceptance testing. The idea is that you start by writing human-readable sentences that describe a feature of your application and how it should work. Then you implement this behavior in software. This description can produce automated tests that will verify that the feature is implemented correctly. On the testing side, BDD tools provide you the features to perform functional or acceptance tests. There are many tools that implement the BDD concept for different languages, including PHP.

This article presents a list of software testing tools to perform Behavior-Driven Development (BDD) for PHP. For each tool you will get a small description of its features and pointers to additional resources that discusses the tool more in details. Feel free to suggest any additional PHP BDD framework or resource that you think might be included in this article. The tools, listed in alphabetical order, are Atoum bdd-extension, Behat, Codeception, Kahlan, pecs, Peridot, pho, phpspec, phpunit-expect.

Updates

* October 30 2018: added atoum/bdd-extension, phpunit-expect and extensions to existing frameworks (API testing, code coverage, …)

Atoum bdd-extension

atoum/bdd-extension allows users of the atoum open source unit testing framework for PHP to write their tests (specs) in a Behavior Driven development fashion.

Web site: https://github.com/atoum/bdd-extension

Behat

Behat is an open source behavior-driven development framework for PHP 5.3 and 5.4 inspired by the Ruby Cucumber BDD framework. Behat uses Gherkin, the same language than Cucumber, to describe features that you can later test with the tool.

Web site: http://behat.org/

Extensions

* Arachne is a Behat extension for testing web services. Similarly to Mink, it exposes multiple methods in a context to facilitate testing of RESTful APIs.

* Behapi is a Behat extension to help write describe features related to HTTP APIs

* MinkExtension is an integration layer between Behat and Mink

* ScenarioStateBehatExtension improve testing a stateless system with Behat

Additional resources

* Behat: The BDD library for PHP

* BDD with Behat

* First impressions of Behat – BDD for PHP

* Intro to Behavior Driven Development with Behat (YouTube video)

Codeception

Codeception is an extension of the famous open source PHP unit testing tool PHPUnit that can be used for acceptance testing. It provides BDD-style readable tests that are written in a PHP Domain Specific Language (DSL). You can execute the test scenario either by a simple PHP Browser or by a browser with Selenium WebDriver. Codeception allows you to execute actions in concurrent sessions.

Web site: http://codeception.com/

Extensions

* Specify allows you to write your Codeception tests in more readable BDD style

* Verify is very tiny wrapper for Codeception assertions, that are aimed to make tests a bit more readable.

Additional resources

* Codeception BDD-style PHP testing

* Ruling the Swarm (of Tests) with Codeception

Kahlan

Kahlan is a full-featured open source unit and BDD test framework a la RSpec/JSpec. Kahlan uses a describe-it syntax and moves testing in PHP one step forward. Kahlan embraces the KISS principle and aims at making Unit and BDD testing fun again.

Web site: https://github.com/crysalead/kahlan

Additional resources

* Faster PHP code coverage

pecs

pecs is a tiny open source behavior-driven development library for PHP 5.3, a la RSpec or JSpec. pecs is greatly inspired by JSpec’s grammar-less syntax.

Web site: https://github.com/noonat/pecs

Peridot

Peridot is an extensible open source PHP testing framework. Your will write you tests using the familiar describe-it syntax, sot that can easily and clearly describe how your code should behave in a language that makes sense. Peridot is event driven, so writing plugins or ad hoc extensions is painless. Peridot events and scopes allow you to easily add test helpers, custom reporters, and plugins.

Web site: http://peridot-php.github.io/

Additional resources

* Testing PHP Apps with Peridot

pho

BDD test framework for PHP, inspired by Jasmine and RSpec. Features a familiar syntax, and a watch command to automatically re-run specs during development. It can also be extended with custom matchers and reporters.

Web site: https://github.com/danielstjules/pho

phpspec

phpspec is an open source PHP tool to drive emergent design by specification. It uses a SpecBDD approach to guide you in the process BDD by letting you write the code in small steps. The object behavior is made up of examples. Examples are encased in public methods, started with it_. or its_. phpspec searches for these methods in your specification to run. You use matchers in phpspec to describe how an object should behave. They are like assertions in xUnit but with a focus on specifying behaviour instead of verifying output. You use the matchers prefixed by should or shouldNot as appropriate.

Web site: http://www.phpspec.net/

Extensions

* phpspec-code-coverage is an extension that generates Code Coverage reports for PhpSpec tests

* phpspec-sort-use-statements is a PhpSpec extension for automatically sorting use statements in generated specifications

Additional resources

* phpspec – Drive Emergent Design by Specification

* Moving to BDD with PHP

* A BDD Workflow With Behat and Phpspec

phpunit-expect

phpunit-expect provides BDD-style assertions for PHPUnit, the reference open source tool for PHP unit testing.

Web site: https://github.com/jpkleemans/phpunit-expect