hhspecify/hhspecify

BDD testing framework for Hack

0.1.2 2015-10-01 01:19 UTC

This package is not auto-updated.

Last update: 2024-04-27 15:37:15 UTC


README

Build Status

HHSpecify is BDD testing framework for Hack, inspired by spock.

Screen Shot

Installation

Installed by composer.

composer require hhspecify/hhspecify

Basic usage

Create a configuration file

Create a configuration file in order to verify the specifications.
Use the configure method to do the setup.

<?hh //partial

use hhspecify\HHSpecify;
use hhspecify\config\ConfigBuilder;
use hhspecify\reporter\SpecificationReporter;

HHSpecify::configure((ConfigBuilder $builder) ==> {

    $package = shape(
        'namespace' => 'vendorname\\spec\\', //The package namespace of the spec
        'packageDirectory' => __DIR__ . '/spec' //The directory of the package spec
    );

    $builder->package($package)
        ->featureReporter(new SpecificationReporter());

});

Create a specification file

It will create a specification file to vendorname/spec.
Specification must implement hhspecify\Specification.

It will specify the specification in the Feature attribute.

use hhspecify\Specification;
use hhspecify\feature\FeatureVerifierBuilder as Feature;

final class StackSpec implements Specification
{

    public function __construct(
        private Stack<int> $stack = new Stack()
    )
    {
    }

    <<Feature("Stack::add")>>
    public function add_value_to_stack(Feature $feature) : void
    {
    }
}

Write a feature specification

It will describe the setup / when / then block.
Block specified in lambda expression.

<<Feature("Stack::add")>>
public function add_value_to_stack(Feature $feature) : void
{
    //setup block - Setup
    $feature->setup(() ==> {
        $this->stack = new Stack();
    });

    //when block - Stimulus
    $feature->when(() ==> {
        $this->stack->add(1);
    });

    //then block - Response
    $feature->then(() ==> {
        invariant($this->stack->count() === 1, 'must have been added value');
    });
}

Verify the specification

In the package root directory run the following command.

vendor/bin/hhspecify

Run the test

composer install
composer test

Run the example

composer install
composer example