More details on dump Utilties introduction
check
PHP utility for unit testing

Function and purpose

Download
Zipped PHP programs and ancillary files
Key methods
TestDoes something equal something else? Eg function returns expected result.
IsTests type or object class
TrapFor investigating the throwing of exceptions
check is a utility for structured testing. Some people call this unit testing. It is a framework for a few test wrappers which is ever so easy to get started with. It is also simple enough for anyone to adjust the code to suit their own development environment.

Examples

Two example PHP programs All in new windows
Run simple demo View source
Run variations on a theme View source

Documentation

Code outline

include('check.php'); etc. Start block... check::StartBlock('First block'); ... some tests check::Is('Should be array','array',$someVar); // Right sort of type check::Test('Does it work',42,$universe->Answer()); // Expected and actual check::Trap('Should throw exception','argument','multiply',null,'cat'); ... more tests ... check::EndBlock(); ... more blocks of tests ... check::Finish();

Getting started

Reference

Calling check::Help() displays the reference. See it now
  • Notes
  • Splitting tests into blocks is de-rigeur. This gives you a structure and makes de-cluttering your results a lot easier.
  • In the examples I have used a reference style of labelling. You can do whatever suits you from simple numbers to full descriptions.
  • Normally output is buffered. Sometimes you want to see what else is going on with checks interleaved with other output. Disable buffering for a block with a second argument to check::StartBlock().
  • check::TestNot() is a funny thing. Use this when you know of a possible rogue result and want it reported if it happens.
  • You can of course put tests in loops. In demoCheck.php there is an example of how the verbosity can be tweaked to de-clutter the results.
  • When trapping on a function that takes a single array as its argument you would call it as follows: check::Trap('T1','empty','maxOfArray',null,array(array(1,2,3))) (note the nested array). An un-nested array here would supply a number of arguments not a single argument.