The expectation component provides prebuilt conditional logical groups based on type and explicit value, as well as exception handling and manual trigger, to validate test results.
Logical Condition Groups
Methods with PHP's built-in type suffixes like asInt, as well as explicit
as, form a logical OR group, similar to a switch case. All other methods
are treated as logical AND:
$this->validate($result0)
// explicit logical OR
// must be exactly (===) this type and value
->as($result1)
// explicit logical AND
// must not be (!==) this type and value
->asNot($result2)
// typed logical OR
// must be exactly (is_int) this type
->asInt()
// typed logical AND
// must be a number (is_numeric) and
// $result0 >= 2 && $result0 <= 6
->asNumberBetween(2, 6);
Valid Exception
To test exceptions in your code, you can set them as an expected valid test result before running the code under test:
$this->expectException(Exception::class);
// code you test
// triggers expected exception
$example = new Example;
Custom Error
For complex test results or cases not yet supported by Reflex, you can manually validate and fail a test by explicitly triggering an error with a descriptive message:
if ($example !== 4)
$this->fail("message")