Key methods |
- check::Test(label,expected,actual)→bool Simple 'do we get the expected result'
- check::TestNot() is the negative truth of Test()
- check::Is(label,type,variable)→bool type can be
- 'string','null','array','boolean'
- 'numeric' ie. is numeric or convertable to a number
- A class name (case sensitive)
- check::Trap(label,message,function name,Object,Arguments)→bool
Testing for exception handling
- label is test identifier
- message
- If there shouldn't be an exception then an empty string
- Otherwise some text fragment found in exception message
- Note this works exclusively on exception message not exception 'type'(sub-class)
- function name is a string being the name of the function or method to be executed
- Object will be null if this is working on a plain function
- Arguments is missing, a scalar (if only one argument) or an array of arguments
- Examples
- ('Zdiv','zero','Divide',$myObject,array(5,0)) // expects to trigger divide by zero
- ('Feline.a','','AddToList',null,'cat') // this shouldn't be an exception
- ('Feline.b','not a cat','AddToList',null,array('dolphin')) // triggers exception
- check::Finish([fileName]) Prints full totals and timestamp. Optionally send output to
file instead. The following tokens can be embedded. #n : Basename of test script.
#d : DDYYMM #t : HHMMSS #f : Fail count. eg check::Finish('#nResults.htm');
|
Other test methods |
- check::Show(label,variable) Dump of variable.
- check::TestNot(label,expected,actual)→bool
Inverse truth of Test(). Used where you know of a result you don't want.
- check::Label(label,[NewLineAfter=false])
Writes just a label to the results. Optionally followed by new line.
|
Blocks of tests
|
The normal structure is repeating StartBlock()...tests ...EndBlock() followed by a final Finish()
It is recommended to follow this pattern. Flush() shouldn't normally be required.
- check::StartBlock(text,[buffering=true])
- Text heading at the start of a block of tests.
- Buffering defaults to true but may be set false if you want immediate reporting.
- Note This doesn't reset counters
- check::EndBlock()
- Block summary
- This resets counters
- See check::ShowOkBlockDetails() below
- check::AnyFailures() Boolean true if any failures in this block ie. since start or last Summary()
- check::ShowOkBlockDetails(Show_flag) Call with false to suppress display of individual tests
if a block has no failures. Default is true.
|
Verbosity adjustment |
- check::PassNone() Test functions still return truth values
- check::PassDot() Dot with no new line
- check::PassOk() 'ok' and new line
- check::PassShort() label, ok and new line
- check::PassLong() label, variable, new line
- check::FailTiny() label and FAIL and new line
- check::FailShort() label, FAIL, variable dumped and new line
- check::FailLong() label, FAIL, variable dumped, message and new line
|
Miscellaneous |
- You need require_once('check.php'); at the top of your code.
- dump.php needs to be in yor include path
- check::Help() displays this information
- Version as file date.
- Contact the author at author@vulpeculox.net
- Website vulpeculox.net
|
Example |
function FailOnNegative($Arg){
if($Arg<0){
throw new Exception('Negative not allowed');
}
}
check::PassLong();
check::StartBlock('Checking examples');
check::Is('E1.a','numeric',Time());
check::Test('E2.a','2011',Date('Y'));
check::Trap('E3.a','Negative','FailOnNegative','',-5);
check::EndBlock();
// more StartBlock()...tests...EndBlock() blocks might go here
check::Finish();
|