given-php/given-php

Smooth syntax to write specs

dev-master 2015-03-15 21:31 UTC

This package is not auto-updated.

Last update: 2024-04-23 00:17:18 UTC


README

Proudly inspired by rspec-given from the Jim Weirich and phpspec.

Basic features

<?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; });
  }
}

Run the specs

$ vendor/bin/given-php run

Todos

  • Refactor the code and have a real flow for the SpecRunner
  • Add a real runner (using Symfony/Command and maybe thephpleague/flysystem)
  • Add a real formatter
  • Handling errors with then(failed()) and then(failedWith('ExceptionType'))
  • Transform PHPErrors into Exceptions
  • Add pending status if then() is empty
  • Add skip status with then($callback, bool|callable $skip = false)
  • Add formats
  • Simple dot [.XF] notation
  • Pretty
  • Null
  • Add reporters
  • JUnit format
  • Handling output with then(showed('expected output'))
  • ? Add test/code generation (phpspec alike)