15/03
2015
dev-master
9999999-devSmooth syntax to write specs
MIT
The Requires
by Thomas Ruiz
Wallogit.com
2017 © Pedro Peláez
Smooth syntax to write specs
Proudly inspired by rspec-given from the Jim Weirich and phpspec., (*1)
<?php namespace spec\Foo;
use Foo;
return describe(Foo::class, with('constructorParam1', 'constructorParam2'), function () {
given('constructorParam1', function () { return 'scalarValue'; });
// $barProphecy will be an instance of PhpSpec\Prophecy\ObjectProphecy
given('constructorParam2', function (Bar $barProphecy) { return $barProphecy->reveal(); });
given(function (Bar $barProphecy) { $barProphecy->baz()->willReturn(3); });
// Isolate further statements
context('when isolated', function () {
given(function (Bar $barProphecy) { $barProphecy->required()->shouldBeCalled(); });
// $that is the instance of the object under specification
when(function (Foo $that) { $that->isolated(); });
when('result', function (Foo $that) { return $that->passToBar('required'); });
// Assertions are (for now) made with simple conditions
then(function ($result) { return $result === 3; });
}
}
$ vendor/bin/given-php run
Smooth syntax to write specs
MIT