2017 © Pedro Peláez
 

library phpcheck

A testing library for PHP loosely based on Haskell's QuickCheck library.

image

callumacrae/phpcheck

A testing library for PHP loosely based on Haskell's QuickCheck library.

  • Tuesday, July 3, 2012
  • by callumacrae
  • Repository
  • 3 Watchers
  • 6 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

PHPCheck

PHPCheck is a testing library for PHP loosely based on Haskell's QuickCheck., (*1)

Installation

There are two ways of getting PHPCheck into your project. The first is to require it as you would any other PHP library:, (*2)

<?php

require_once('PHPCheck/src/PHPCheck.php');

The second is to use Composer. Either add callumacrae/PHPCheck to your composer.json, or create one containing the following:, (*3)

{
    "require": {
        "callumacrae/PHPCheck": "master"
    }
}

Then run the following two commands:, (*4)

curl -s http://getcomposer.org/installer | php
php composer.phar install

That will download PHPCheck into vendor/callumacrae/PHPCheck. You can then either require the file as above, or use Composers awesome autoloader:, (*5)

<?php

require 'vendor/autoload.php';

Usage

To start using PHPCheck, include phpcheck.php and create a new instance of the PHPCheck object. Then, use the $phpcheck->claim method to make "claims". It accepts the following arguments:, (*6)

$phpcheck->claim( string $testName , function $predicate [ , array $specifiers ] )

$testName is the name of the test (obviously)., (*7)

$predicate is a function which returns true if the test passes. Anything else is a fail., (*8)

$specifiers is an optional array of specifiers to be passed to the predicate function. They are usually like this:, (*9)

<?php

$specifiers = array(
    PHPCheck::Integer(5, 10), // An integer between 5 and 10
    PHPCheck::String(PHPCheck::integer(2, 4), 'a'), // 2 to 4 "a"s
    PHPCheck::OneOf(array('cat', 'dog')), // Either cat or dog
);

Demo

<?php

require 'vendor/autoload.php';

$tests = new PHPCheck;

$tests->group('Numbers');

$tests->claim('Less than', function ($a, $b) {
    return ($a < $b);
}, array(
    PHPCheck::Number(0, 10),
    PHPCheck::Number(10, 20);
));

$tests->check();

License

Creative Commons License, (*10)

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License., (*11)

The Versions

03/07 2012

dev-master

9999999-dev https://github.com/callumacrae/PHPCheck

A testing library for PHP loosely based on Haskell's QuickCheck library.

  Sources   Download

Creative Commons Attribution-ShareAlike 3.0 Unported License

The Requires

  • php >=5.3.0

 

testing php quickcheck