PHPackages                             php-kitchen/code-specs - 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. php-kitchen/code-specs

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

php-kitchen/code-specs
======================

BDD extension for PHPUnit that allows to write tests as a specifications in a human-readable format.

v4.0.1(8y ago)89771[2 issues](https://github.com/php-kitchen/code-specs/issues)[1 PRs](https://github.com/php-kitchen/code-specs/pulls)4MITPHPPHP ^7.1CI failing

Since Jun 1Pushed 4y ago3 watchersCompare

[ Source](https://github.com/php-kitchen/code-specs)[ Packagist](https://packagist.org/packages/php-kitchen/code-specs)[ Docs](https://github.com/php-kitchen/code-specs)[ RSS](/packages/php-kitchen-code-specs/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependencies (3)Versions (12)Used By (4)

 [![](https://github.com/php-kitchen/code-specs/raw/master/docs/logo.png)](https://github.com/php-kitchen/code-specs/blob/master/docs/logo.png)

 [![Build Status](https://camo.githubusercontent.com/a46ede8f1cf4c87b575ab49df1dc7c6629cfd9ca029bdda468d9637c652b2adb/68747470733a2f2f7472617669732d63692e6f72672f7068702d6b69746368656e2f636f64652d73706563732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/php-kitchen/code-specs) [![Code Coverage](https://camo.githubusercontent.com/c6f4cbdf38e07abe967db9173f710088aa1664433283eee8cdaf6a30980cd159/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f7068702d6b69746368656e2f636f64652d73706563732f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/php-kitchen/code-specs?branch=master) [![Code Quality](https://camo.githubusercontent.com/53745256f92bcb92d23a9f9baa8bda0a6de141860fd6e497631741700e14c978/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7068702d6b69746368656e2f636f64652d73706563732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/php-kitchen/code-specs/?branch=master) [![Latest Stable Version](https://camo.githubusercontent.com/665487a251968fbb98e92abd5528f3ebaa4c7138d13f74bcbee7295b74839e3f/68747470733a2f2f706f7365722e707567782e6f72672f7068702d6b69746368656e2f636f64652d73706563732f762f737461626c652e737667)](https://packagist.org/packages/php-kitchen/code-specs) [![Monthly Downloads](https://camo.githubusercontent.com/aaf7e860d4e06512b4281ef8845ac91ae2fd557432b082aee0e62e3ac478ac20/68747470733a2f2f706f7365722e707567782e6f72672f7068702d6b69746368656e2f636f64652d73706563732f642f6d6f6e74686c79)](https://packagist.org/packages/php-kitchen/code-specs) [![Total Downloads](https://camo.githubusercontent.com/674efc36fb89c1f0bbb05e6b5d101099758b4e1221a4fd3e24603a1105c3428f/68747470733a2f2f706f7365722e707567782e6f72672f7068702d6b69746368656e2f636f64652d73706563732f642f746f74616c2e737667)](https://packagist.org/packages/php-kitchen/code-specs) [![License](https://camo.githubusercontent.com/f58da02836556f0e9f11762df46255005832bb22fae1b3bf6a8069c777054b82/68747470733a2f2f706f7365722e707567782e6f72672f7068702d6b69746368656e2f636f64652d73706563732f6c6963656e73652e737667)](https://packagist.org/packages/php-kitchen/code-specs)

NOTICE: Library is under refactoring for release of V5.0.0 and docs reflect the new style of specs
==================================================================================================

[](#notice-library-is-under-refactoring-for-release-of-v500-and-docs-reflect-the-new-style-of-specs)

Code Specs isn't just another tests library - it's the way you design your solutions. The Specs Way.

Code Specs is built as a PHPUnit plugin(with Codeception support as well) for writing BDD style Unit tests in a specification way using human-readable format.

Goal of Code Specs is to add a bunch of cool tools for unit testing and show a way of representing unit tests as a behavior specifications that describes specific class behavior in variety of use-cases.

The min hero of Code Specs that does the magic is Tester. Tester represents an actor who ensures you code pass specifications(yes, like in [Codeception](https://github.com/Codeception/Codeception) - this library expired by Codeception). See iy by yourself:

```
namespace Specs\Unit;

use PHPKitchen\CodeSpecs\Base\Specification;
use PHPKitchen\CodeSpecs\Actor\I;

/**
 * Specification of {@link IncomeCalculator}
 *
 * @author Dima Kolodko
 */
class IncomeCalculatorTest extends Specification {
    private const EXPECTED_TAX_FOR_FIRST_LEVEL_TAX_RULE = 4500;
    private const EXPECTED_TAX_FOR_SECOND_LEVEL_TAX_RULE = 7200;
    private const EXPECTED_TAX_FOR_THIRD_LEVEL_TAX_RULE = 30000;
    private const INCOME_AFTER_APPLYING_FIRST_LEVEL_TAX_RULE = 300000;

    /**
     * @test
     */
    public function calculateTaxBehavior() {
        $clientsPayments = []; // dummy variable, just for example
        $hoursSpentWorking = 160; // dummy variable, just for example
        $service = new IncomeCalculator($clientsPayments, $hoursSpentWorking);
        I::describe('income tax calculations');

        I::expect('for income less that 50 000 calculator use 10% tax rule', function () use ($service) {
            I::lookAt('first level income tax')
                ->seeNumber($service->calculateTax())
                ->isNotEmpty()
                ->isEqualTo(self::EXPECTED_TAX_FOR_FIRST_LEVEL_TAX_RULE);
        });

        I::expect('for income between 50 000 and 100 000 calculator use 12% tax rule', function () use ($service) {
            I::lookAt('second level income tax')
                ->seeNumber($service->calculateTax())
                ->isNotEmpty()
                ->isEqualTo(self::EXPECTED_TAX_FOR_SECOND_LEVEL_TAX_RULE);
        });

        I::expect('for income more than 100 000 calculator use 20% tax rule', function () use ($service) {
            I::lookAt('second level income tax')
                ->seeNumber($service->calculateTax())
                ->isNotEmpty()
                ->isEqualTo(self::EXPECTED_TAX_FOR_THIRD_LEVEL_TAX_RULE);
        });
    }

    /**
     * @test
     */
    public function calculateWithTaxBehavior() {
        $clientsPayments = []; // dummy variable, just for example
        $hoursSpentWorking = 160; // dummy variable, just for example
        $service = new IncomeCalculator($clientsPayments, $hoursSpentWorking);

        I::describe('Net income calculation');
        I::expect('calculator calculates income with tax using 10% tax rule for income less that 50 000');

        I::lookAt('income tax')
            ->seeNumber($service->calculateWithTax())
            ->isNotEmpty()
            ->isEqualTo(self::INCOME_AFTER_APPLYING_FIRST_LEVEL_TAX_RULE);

    }
}
```

CodeSpecs also decorates errors output so, for example, if "IncomeCalculator" service from example above will incorrectly calculate income the error output will include following message(example of output in PHPStorm):

[![picture alt](docs/en/failed-spec.png "Error output")](docs/en/failed-spec.png)

Requirements
------------

[](#requirements)

**`PHP >= 7.4` is required.**

**`PHPUnit >= 9.1` is required.**

Getting Started
---------------

[](#getting-started)

Run the following command to add CodeSpecs to your project's `composer.json`. See [Packagist](https://packagist.org/packages/php-kitchen/code-specs) for specific versions.

```
composer require --dev php-kitchen/code-specs
```

Or you can copy this library from:

- [Packagist](https://packagist.org/packages/php-kitchen/code-specs)
- [Github](https://github.com/php-kitchen/code-specs)

Then you can use CodeSpecs in your test simply extending from `Specification` class. Example:

```
use PHPKitchen\CodeSpecs\Base\Specification;

class YourTest extends Specification {

    /**
     * @test
     */
    public function myMethodBehavior() {
        I::lookAt('my dummy variable')
            ->seeBool(true)
            ->isFalse();
    }
}
```

**Note:** *If you want to use CodeSpecs with Codeception read [Codeception integration guide](docs/en/integrations/codeception.md)*

For additional information and guides go to the [project documentation](docs/README.md)See [changes log](docs/CHANGELOG.md) for information about changes in releases and [update guide](docs/UPDATE-GUIDE.md) for information about upgrading to a next major version.

Contributing
------------

[](#contributing)

If you want to ask any questions, suggest improvements or just to talk with community and developers, [join our server at Discord](https://discord.gg/Ez5VZhC)Read [organization contributing rules](https://github.com/php-kitchen/conventions/blob/master/CONTRIBUTING.md) for additional information.

### Spreading the Word

[](#spreading-the-word)

Acknowledging or citing CodeSpecs is as important as direct contributions.

If you are using CodeSpecs as part of an OpenSource project, a way to acknowledge it is to use a special badge in your README: [![Tested By](https://camo.githubusercontent.com/72981c1ba31ca807146cdb403287e010565bdc86206852ae0458a4636fad5847/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f54657374656425323025323042792d436f646553706563732d627269676874677265656e2e737667)](https://github.com/php-kitchen/code-specs)

If your code is hosted at GitHub, you can place the following in your README.md file to get the badge:

```
[![CodeSpecs](https://img.shields.io/badge/Tested_By-CodeSpecs-brightgreen.svg?style=flat)](https://github.com/php-kitchen/code-specs)
```

or use regular HTML:

```

```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~60 days

Recently: every ~32 days

Total

10

Last Release

3087d ago

Major Versions

0.0.3 → 1.0.02016-10-19

1.0.0 → 2.0.02017-07-24

2.0.1 → 3.0.02017-11-14

v3.0.1 → v4.0.02017-11-28

PHP version history (4 changes)0.0.1PHP &gt;=5.6.0

1.0.0PHP ^5.6|^7.0

2.0.0PHP ^7.0

3.0.0PHP ^7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/cb438037616dc8ee90a1291de026217f8355f4fa24b0d05ac1a4dc2ecc1bd0a8?d=identicon)[prowwid](/maintainers/prowwid)

---

Top Contributors

[![prowwid](https://avatars.githubusercontent.com/u/3070281?v=4)](https://github.com/prowwid "prowwid (29 commits)")

---

Tags

phpunitspecificationBDDtestsextensionspectesterunit-tests

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/php-kitchen-code-specs/health.svg)

```
[![Health](https://phpackages.com/badges/php-kitchen-code-specs/health.svg)](https://phpackages.com/packages/php-kitchen-code-specs)
```

###  Alternatives

[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)[janmarek/mockista

Mockista is library for mocking, which I've written, because I find mocking in PHPUnit awful.

29221.0k28](/packages/janmarek-mockista)[code-distortion/adapt

A Laravel package that builds databases for your tests, improving their speed.

2835.5k](/packages/code-distortion-adapt)[friends-of-phpspec/phpspec-code-coverage

Generate Code Coverage reports for PhpSpec tests

202.6M125](/packages/friends-of-phpspec-phpspec-code-coverage)[aik099/phpunit-mink

Library for using Mink in PHPUnit tests. Supports session sharing between tests in a test case.

72136.2k1](/packages/aik099-phpunit-mink)

PHPackages © 2026

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