Giter Club home page Giter Club logo

phpcheck's Introduction

PHPCheck

PHPCheck is a testing library for PHP loosely based on Haskell's QuickCheck.

Installation

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

<?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:

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

Then run the following two commands:

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:

<?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:

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

$testName is the name of the test (obviously).

$predicate is a function which returns true if the test passes. Anything else is a fail.

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

<?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

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

phpcheck's People

Contributors

callumacrae avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.