Skip to content

thekid/behave

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 

Repository files navigation

Behaviour tests for PHP functionality

This tests PHP functionality using a fluent function-based DSL. In contrast to the PHPT tests, all tests are run in the same interpreter instance, speeding up functional verification of a PHP implementation drastically.

Prerequisites

This library requires PHP 5.5.

Running the tests

$ find src/test -name '*.php' | xargs php src/behaves.php
# [...]
OK, XXX succeeded, 0 failed (time taken: X.XXX seconds)

Writing tests

A basic test looks resides in a namespace mapping to the directory and including the fixture's name itself.

Functions

namespace test\php\ext\date\date_create;

// @see http://de3.php.net/manual/de/datetime.construct.php
// @see http://de3.php.net/manual/de/datetime.formats.php
return new \behaviour\of\TheFunction('date_create', [
  'before' => function() {
    date_default_timezone_set('Europe/Berlin');
  },

  'describe' => [
    it('returns current date per default', function() {
      shouldEqual(time(), date_create()->getTimestamp());
    }),
  ]
]);

Classes

namespace test\php\ext\reflection\ReflectionClass;

class Fixture { }

// @see http://de3.php.net/manual/de/class.reflectionclass.php
return new \behaviour\of\TheClass('ReflectionClass', [
  it('can be constructed with a class name', function() {
    shouldBe(\ReflectionClass::class, new \ReflectionClass(Fixture::class));
  }),

  // @see http://de3.php.net/manual/de/reflectionclass.getname.php
  its('getName', [
    it('returns the class\' name', function() {
      shouldEqual(Fixture::class, (new \ReflectionClass(Fixture::class))->getName());
    }),
  ]),
]);

Test API

/** Creates a new assertion generator with a description **/
it(string $description, callable $verification) : generator<Assertion>

/** Creates a new parameterized assertion generator **/
it(string $description, array $values, callable $verification) : generator<Assertion>

/** Creates a new assertion generator for a given group **/
its(string $group, array $assertions) : generator<Assertion>

/** Create a new parameterized assertion generator **/
given(mixed $value, generator<Assertion> $assertions) : generator<Assertion>

Skipping tests

skip('To be implemented')->it('can be used without arguments', function() {
  // ...
});

About

Behaviour tests for PHP functionality

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages