PHPackages                             codeception/specify - 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. codeception/specify

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

codeception/specify
===================

BDD code blocks for PHPUnit and Codeception

2.0.0(4y ago)15910.4M—6%24[5 issues](https://github.com/Codeception/Specify/issues)[1 PRs](https://github.com/Codeception/Specify/pulls)20MITPHPPHP &gt;=7.4.0

Since Jul 25Pushed 3y ago9 watchersCompare

[ Source](https://github.com/Codeception/Specify)[ Packagist](https://packagist.org/packages/codeception/specify)[ RSS](/packages/codeception-specify/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (24)Used By (20)

Specify
=======

[](#specify)

BDD style code blocks for [PHPUnit](https://phpunit.de/) or [Codeception](https://codeception.com/)

[![Latest Stable Version](https://camo.githubusercontent.com/c0538bdc87078a02e275164cf6e614adb2b8c0566b0527a42ba8241b3022ea46/68747470733a2f2f706f7365722e707567782e6f72672f636f646563657074696f6e2f737065636966792f762f737461626c65)](https://packagist.org/packages/codeception/specify)[![Total Downloads](https://camo.githubusercontent.com/a2ed15d6cadff7110eac9b754735503bd140bdaa81c068a78423708246d91745/68747470733a2f2f706f7365722e707567782e6f72672f636f646563657074696f6e2f737065636966792f646f776e6c6f616473)](https://packagist.org/packages/codeception/specify)[![Latest Unstable Version](https://camo.githubusercontent.com/bf7b9416b17014892017870ff88ccded237c5cc3266c75185ed75019b9c3916f/68747470733a2f2f706f7365722e707567782e6f72672f636f646563657074696f6e2f737065636966792f762f756e737461626c65)](https://packagist.org/packages/codeception/specify)[![License](https://camo.githubusercontent.com/53d8636abdb78ceb21302ecfd73f668037dc75197f3ca3384f55985ff5cecaa5/68747470733a2f2f706f7365722e707567782e6f72672f636f646563657074696f6e2f737065636966792f6c6963656e7365)](https://packagist.org/packages/codeception/specify)[![StandWithUkraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md)

Specify allows you to write your tests in more readable BDD style, the same way you might have experienced with [Jasmine](https://jasmine.github.io/). Inspired by MiniTest of Ruby now you combine BDD and classical TDD style in one test.

Installation
------------

[](#installation)

*Requires PHP &gt;= 7.4*

- Install with Composer:

```
composer require codeception/specify --dev

```

- Include `Codeception\Specify` trait in your tests.

Usage
-----

[](#usage)

Specify `$this->specify` method to add isolated test blocks for your PHPUnit tests!

```
public function testValidation()
{
    $this->assertInstanceOf('Model', $this->user);

    $this->specify('username is required', function() {
        $this->user->username = null;
        $this->assertFalse($this->user->validate(['username']));
    });

    $this->specify('username is too long', function() {
        $this->user->username = 'toolooooongnaaaaaaameeee';
        $this->assertFalse($this->user->validate(['username']));
    });
}
```

### BDD Example

[](#bdd-example)

Specify supports `describe-it` and `describe-should` BDD syntax inside PHPUnit

```
public function testValidation()
{
    $this->describe('user', function () {
        $this->it('should have a name', function() {
            $this->user->username = null;
            $this->assertFalse($this->user->validate(['username']));
        });
    });

    // you can use chained methods for better readability:
    $this->describe('user')
        ->should('be ok with valid name', function() {
            $this->user->username = 'davert';
            $this->assertTrue($this->user->validate(['username']));
        })
        ->shouldNot('have long name', function() {
            $this->user->username = 'toolooooongnaaaaaaameeee';
            $this->assertFalse($this->user->validate(['username']));
        })
        // empty codeblocks are marked as Incomplete tests
        ->it('should be ok with valid name')
    ;
}
```

### Specify + Verify Example

[](#specify--verify-example)

Use [Codeception/Verify](https://github.com/Codeception/Verify) for simpler assertions:

```
public function testValidation()
{
    $this->specify('username is too long', function() {
        $this->user->username = 'toolooooongnaaaaaaameeee';
        expect_not($this->user->validate(['username']));
    });

    $this->specify('username is ok', function() {
        $this->user->username = 'davert';
        expect_that($this->user->validate(['username']));
    });
}
```

Use Case
--------

[](#use-case)

This tiny library makes your tests readable by organizing them in nested code blocks. This allows to combine similar tests into one but put them inside nested sections.

This is very similar to BDD syntax as in RSpec or Mocha but works inside PHPUnit:

```
