dev-master
9999999-dev https://github.com/callumacrae/PHPCheckA testing library for PHP loosely based on Haskell's QuickCheck library.
Creative Commons Attribution-ShareAlike 3.0 Unported License
The Requires
- php >=5.3.0
testing php quickcheck
Wallogit.com
2017 © Pedro Peláez
A testing library for PHP loosely based on Haskell's QuickCheck library.
PHPCheck is a testing library for PHP loosely based on Haskell's QuickCheck., (*1)
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';
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
);
<?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();
, (*10)
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License., (*11)
A testing library for PHP loosely based on Haskell's QuickCheck library.
Creative Commons Attribution-ShareAlike 3.0 Unported License
testing php quickcheck