PHPackages                             rmiller/behat-spec - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. rmiller/behat-spec

ActiveLibrary[Testing &amp; Quality](/categories/testing)

rmiller/behat-spec
==================

Behat and PhpSpec integration

0.5.0(9y ago)5321.7k6[6 issues](https://github.com/richardmiller/BehatSpec/issues)[1 PRs](https://github.com/richardmiller/BehatSpec/pulls)8MITPHPPHP &gt;=5.4

Since Nov 4Pushed 9y ago6 watchersCompare

[ Source](https://github.com/richardmiller/BehatSpec)[ Packagist](https://packagist.org/packages/rmiller/behat-spec)[ Docs](https://github.com/richardmiller/BehatSpec)[ RSS](/packages/rmiller-behat-spec/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (11)Used By (8)

BehatSpec
=========

[](#behatspec)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/d6a9735ca325404278d50c818d16e65508748fc2b2867dab99e6749bcf2d0628/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f726963686172646d696c6c65722f4265686174537065632f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/richardmiller/BehatSpec/?branch=master)[![Build Status](https://camo.githubusercontent.com/2b2698703a85641170da888750a88743d70501b54367d10f52f8b7315592fd11/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f726963686172646d696c6c65722f4265686174537065632f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/richardmiller/BehatSpec/build-status/master)

What
----

[](#what)

Integration between [Behat](http://docs.behat.org/en/v3.0/) and [PhpSpec](http://phpspec.net/).

- Creates specs for any missing classes encountered when running behat
- Adds examples for any missing methods encountered when running behat
- Executes the phpspec run command after this to add the described class/method

Why
---

[](#why)

This is useful when rather than using the Behat context to run an application through its UI, it is instead used to implement the domain model. For more information on this way of using Gherkin features to drive domain modelling read Everzet's post on [Modelling by Example](http://everzet.com/post/99045129766/introducing-modelling-by-example)

When running a feature with a Context that contains a new class that does not exist or a method you will get a fatal error. If using PhpSpec the next step would be to start specifying that class using the describe command. This set of extensions provides integration between Behat and PhpSpec so that instead of a fatal error you can choose to run the describe command for the missing class automatically.

It also uses my [ExemplifyExtension](https://github.com/richardmiller/ExemplifyExtension)so that you can automatically add examples for missing methods in a similar way.

After describing a class or method in this way the `phpspec run` command can be used to automatically create the class or model. Since this is the typical next step in most cases, this extension automates that by asking you if you would like to do that next.

### An Example

[](#an-example)

So to use an example from the blog post linked above:

```
/**
 * @Given a product named :name and priced £:price was added to the catalogue
 */
public function aProductNamedAndPricedWasAddedToTheCatalogue($name, Money $price)
{
    $aProduct = Product::namedAndPriced($name, $price);
    $this->catalogue->add($aProduct);
}

```

Running the feature relating to this context would result in a fatal exception normally. Instead you get a simple error and the offer to create a spec for the missing class:

[![Product not found](/docs/images/error.png?raw=true)](/docs/images/error.png?raw=true)

The spec is created followed by an offer to run `phpspec run`:

[![Spec created](/docs/images/spec-created.png?raw=true)](/docs/images/spec-created.png?raw=true)

Which asks to create the class:

[![Created Product?](/docs/images/create.png?raw=true)](/docs/images/create.png?raw=true)

[![Product created](/docs/images/product-created.png?raw=true)](/docs/images/product-created.png?raw=true)

Running Behat again will result in a similar process for the `namedAndPriced` method. Where an example for the method will be added to the spec and the method added to the class.

How
---

[](#how)

### Installation

[](#installation)

This package provides an extension for PhpSpec and an extension for Behat. Both need to be enabled for the full functionality.

Requires:

- Behat 3.0+
- PhpSpec 3.0+
- PHP 5.6+

Require the extension:

```
$ composer require --dev rmiller/behat-spec:^0.5

```

In order to use `BehatSpec` with PHPSpec 2.0 series, use `0.3.*` version series:

```
$ composer require --dev rmiller/behat-spec:0.3.*
```

To get the phpspec run command running, you need to use latest phpspec &gt;2.1. Otherwise that functionality will silently fail.

### Configuration

[](#configuration)

Activate the Behat extension by specifying its class in your `behat.yml`:

```
# behat.yml
# ...
extensions:
    RMiller\BehatSpec\Extension\BehatSpecExtension\BehatExtension:
        path:  bin/phpspec #default value is bin/phpspec
        config:  path/to/phpspec.yml #optional
```

Activate the PhpSpec extension by specifying its class in your `phpspec.yml`:

```
# phpspec.yml
extensions:
    RMiller\BehatSpec\Extension\BehatSpecExtension\PhpSpecExtension: ~
```

Additional configuration can be provided for the running of the `phpspec run` command:

It defaults to `bin/phpspec` for the path of phpspec and to run after the describe command. These can be overridden as follows:

```
# phpspec.yml
rerunner:
    path: vendor/bin/phpspec
    commands: [describe, exemplify, your_own_fancy_command]
    config: path/to/phpspec.yml #optional

extensions:
    RMiller\BehatSpec\Extension\BehatSpecExtension\PhpSpecExtension: ~
```

### Some Details

[](#some-details)

This package pulls together some other PhpSpec and Behat extensions which can also be used standalone:

#### PhpSpec

[](#phpspec)

- [PhpSpecRunExtension](https://github.com/richardmiller/PhpSpecRunExtension)
- [ExemplifyExtension](https://github.com/richardmiller/ExemplifyExtension)

#### Behat

[](#behat)

- [PhpSpecExtension](https://github.com/richardmiller/PhpSpecExtension)
- [ErrorExtension](https://github.com/richardmiller/ErrorExtension)

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community25

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~117 days

Recently: every ~2 days

Total

8

Last Release

3392d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/442882d0e62a3acd7f3480cc8a07beeb3098dadbaaecb501eea945374ce55e1b?d=identicon)[mr\_r\_miller](/maintainers/mr_r_miller)

---

Top Contributors

[![ek9](https://avatars.githubusercontent.com/u/17393048?v=4)](https://github.com/ek9 "ek9 (33 commits)")[![richardmiller-zz](https://avatars.githubusercontent.com/u/783827?v=4)](https://github.com/richardmiller-zz "richardmiller-zz (23 commits)")[![pocky](https://avatars.githubusercontent.com/u/204451?v=4)](https://github.com/pocky "pocky (16 commits)")[![richardmiller](https://avatars.githubusercontent.com/u/93760858?v=4)](https://github.com/richardmiller "richardmiller (11 commits)")[![jakubzapletal](https://avatars.githubusercontent.com/u/983464?v=4)](https://github.com/jakubzapletal "jakubzapletal (4 commits)")

---

Tags

BDDStoryBDDSpecBDD

### Embed Badge

![Health badge](/badges/rmiller-behat-spec/health.svg)

```
[![Health](https://phpackages.com/badges/rmiller-behat-spec/health.svg)](https://phpackages.com/packages/rmiller-behat-spec)
```

###  Alternatives

[behat/behat

Scenario-oriented BDD framework for PHP

4.0k96.8M2.0k](/packages/behat-behat)[phpspec/phpspec

Specification-oriented BDD framework for PHP 7.1+

1.9k36.7M3.1k](/packages/phpspec-phpspec)[bossa/phpspec2-expect

Helper that decorates any SUS with a phpspec lazy object wrapper

741.8M87](/packages/bossa-phpspec2-expect)[sensiolabs/behat-page-object-extension

Page object extension for Behat

1166.5M27](/packages/sensiolabs-behat-page-object-extension)[dvdoug/behat-code-coverage

Generate Code Coverage reports for Behat tests

593.6M37](/packages/dvdoug-behat-code-coverage)[soyuka/contexts

Behatch contexts

282.1M11](/packages/soyuka-contexts)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
