Source of testCheck.php
<?php /**/ ?><?php
/* Exercise check */
require_once('check.php');
print("<h1>Testing check functions</h1>
The purpose of this is to deliberately exercise the <b>check</b> functions.
<p>
Lots of <i>FAIL</i>s are expected. These should be at the 'F' labels.<br>
You will need to look at the <a target=\"_blank\" href=\"hfile.php?file=testCheck.php\">source code</a> for this to make sense.<br>
");
/* something to play with */
class foo {
function FailOnNegative($Arg){
if($Arg<0){
throw new Exception('Negative not allowed');
}
}
}
$fooObj = new foo();
function BareFailOnNegative($Arg){
if($Arg<0){
throw new Exception('Negative not allowed');
}
}
/* tests start here */
check::StartBlock('Basic pass/fail');
check::Test('P1.a',1,1); // ok
check::PassNone();
check::Test('P1.b',1,1); // nothing
check::PassDot();
check::Test('P1.c',1,1); // dot
check::PassOk();
check::Test('P1.d',1,1); // ok
check::PassShort();
check::Test('P1.e',1,1); // label + ok
check::PassLong();
check::Test('P1.f',1,1); // label + value
check::Test('F1.a','Exp','Act'); // + args
check::FailTiny();
check::Test('F1.b','Exp','Act'); // no args
check::FailLong();
check::Test('F1.c','Exp','Act'); // + args + message
check::EndBlock();
//=================================================
check::StartBlock('Type checking');
check::Is('P2.a','string','cat');
check::Is('F2.b','string',456);
check::Is('F2.c','string',$fooObj);
check::Is('P3.a','array',array('cat','dog','weasle'));
check::Is('P3.b','array',array());
check::Is('F3.c','array','cat');
check::Is('F3.d','array',null);
check::Is('P4.a','boolean',true);
check::Is('P4.b','boolean',false);
check::Is('F4.c','boolean','');
check::Is('F4.d','boolean',null);
check::Is('P5.a','numeric','123');
check::Is('P5.b','numeric',123);
check::Is('P5.c','numeric',true);
check::Is('P6.a','null',null);
check::Is('F6.a','null','');
check::Is('F6.b','null',0);
check::Is('P9.a','foo',$fooObj);
check::Is('F9.b','foox',$fooObj);
check::EndBlock();
//=================================================
check::StartBlock('Exceptions');
check::Trap('P7.a','','BareFailOnNegative',null,6);
check::Trap('P7.b','Negative not allowed','BareFailOnNegative',null,-6);
check::Trap('P7.c','Neg','BareFailOnNegative',null,-6);
check::Trap('F7.d','silly','BareFailOnNegative',null,-6);
check::Trap('F7.e','Neg','BareFailOnNegative',null,6);
check::Trap('P8.a','','FailOnNegative',$fooObj,6);
check::Trap('P8.b','Negative not allowed','FailOnNegative',$fooObj,-6);
check::Trap('P8.c','Neg','FailOnNegative',$fooObj,-6);
check::Trap('F8.d','silly','FailOnNegative',$fooObj,-6);
check::Trap('F8.e','Neg','FailOnNegative',$fooObj,6);
check::EndBlock();
check::Finish();
check::Help(); // convenience display for the novice
?>