hhspecify / hhspecify
BDD testing framework for Hack
Installs: 8
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 2
Language:Hack
Requires
- hhvm: >=3.6.0
Requires (Dev)
- expect/peridot-expect-plugin: ~3.0
- peridot-php/peridot: ~1.15
- peridot-php/peridot-dot-reporter: ~1.0
- phpspec/prophecy: ~1.4
This package is not auto-updated.
Last update: 2024-04-27 15:37:15 UTC
README
HHSpecify is BDD testing framework for Hack, inspired by spock.
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