PHPackages                             sizuhiko/spec-php - 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. sizuhiko/spec-php

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

sizuhiko/spec-php
=================

This is forked Spec-PHP, and support RSpec2 syntaxs, composer.

0.9.6.2(12y ago)315.9k21MITPHPPHP &gt;=5.3.2

Since Feb 14Pushed 10y ago1 watchersCompare

[ Source](https://github.com/sizuhiko/Spec-PHP)[ Packagist](https://packagist.org/packages/sizuhiko/spec-php)[ RSS](/packages/sizuhiko-spec-php/feed)WikiDiscussions develop Synced 2d ago

READMEChangelog (3)Dependencies (3)Versions (6)Used By (1)

Spec for PHP
============

[](#spec-for-php)

Spec for PHP is a tool to implement Behaviour-Driven Development specification files. It's inspired on [RSpec](http://relishapp.com/rspec) from the Ruby world.

It builds on top of [PHPUnit](http://www.phpunit.de) and [Hamcrest](http://code.google.com/p/hamcrest/)projects to offer mature and solid functionality and borrow the current industry support for those projects.

The intent when implementing Spec was to mix normal PHP code and a more natural language syntax to express expectations. Writing the test code in pure PHP is great because that is how you are going to use it in your application and IDE's offer autocompletion for it. However, assertions are difficult to express and difficult to read with PHP's syntax, thus it makes sense to write them differently.

To be able to parse Spec's syntax there is an on the fly transformation that generates valid PHP code. Code generation has its drawbacks, specially when there is a need to debug a problem, the source file and the executed one are different so it becomes a nighmare to know what's going on. Spec takes this into account and will try as hard as possible to generate code that keeps the original line numbers the same. This is of great help since you can go to the line number reported in an exception and actually see the statement that failed. Check the "How does it work?" section for more details.

> Check [the documentation](http://drslump.github.com/Spec-PHP/) for further details.

Features
--------

[](#features)

*Spec for PHP* is being actively developed and while functional doesn't have all of its features implemented. As thus it should be considered *alpha* quality software for the time being.

### Working features

[](#working-features)

- *Describe* and *It* block parsers
- Natural language expectations parser
- Coordinated expectations (and, or, but)
- *Before* and *After* blocks
- Run expectations against collections/arrays (all, any, none)
- Parametrized *It* blocks
- Annotations support (@group, @skip, @todo, @throw, ...)
- Custom CLI runner tool
- PHPUnit integration
- Use annotation to inherit from custom PHPUnit\_TestCase class (ie: Zend\_Test)
- Matcher factory to create matchers with a callback function
- Any RSpec2 features (subject, its)

### Upcoming

[](#upcoming)

- Review configurable options and extension points

### Later

[](#later)

- Additional matchers
- Better descriptions for expectation failures
- Port features from RSpec 2
- First class integration of Mock frameworks (PHPUnit, Mockery, ...)

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

[](#requirements)

- PHP 5.3
- Composer

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

[](#installation)

Using composer

Add the library to your project's `composer.json` - something like this:

```
{
    "require": {
        "sizuhiko/spec-php": "0.9.*"
    }
}

```

Or, Add the following to your `composer.json` from CLI:

```
composer require sizuhiko/spec-php:0.9.*

```

To do a test run, simply checkout the repository to get the tests directory and run the following commands:

```
cd tests/
phpunit AllTests.php

```

Also try the custom cli runner:

```
spec4php tests

```

Example
-------

[](#example)

```
