2017 © Pedro Peláez
 

library given-php

Smooth syntax to write specs

image

given-php/given-php

Smooth syntax to write specs

  • Sunday, March 15, 2015
  • by thomasruiz
  • Repository
  • 1 Watchers
  • 2 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

given-php

Proudly inspired by rspec-given from the Jim Weirich and phpspec., (*1)

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
  • 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)

The Versions

15/03 2015

dev-master

9999999-dev

Smooth syntax to write specs

  Sources   Download

MIT

The Requires

 

by Thomas Ruiz