public
Description: PHP5 Unit Testing Framework
Home | Edit | New

Assertion Reference

In all examples, [$msg] is optional, and if provided will be displayed on a failed test.

Basic Single-Part Assertions

methodName($params, [$optional]) Description
assertTrue($value, [$msg]) Tests if $value evaluates to true. This is a strict type comparison, so only a boolean true will pass.
assertFalse($value, [$msg]) Tests if $value evaluates to false. This is a strict type comparison, so only a boolean false will pass.
assertNull($value, [$msg]) Tests if $value is evaluates to null. This is a strict type comparison, so only true null will pass.
assertNotNull($value, [$msg]) Tests if $value evaluates to anything but null. This is a strict type comparison, so anything but null will pass.

Basic Two-Part Assertions

methodName($params, [$optional]) Description
assertEqual($expected, $actual, [$msg]) Tests that $expected equals $actual, using a loose type (==) comparison.
assertNotEqual($expected, $actual, [$msg]) Tests that $expected does not equal $actual, using a loose type (!=) comparison.
assertIdentical($expected, $actual, [$msg]) Tests that $expected is identical to $actual, using a strict type (===) comparison.
assertNotIdentical($expected, $actual, [$msg]) Tests that $expected is not identical to $actual, using a strict type (!==) comparison.

Complex Assertions

methodName($params, [$optional]) Description
assertIsA($object, $classname, [$msg]) Tests that $object is of type $classname. $classname can be an object, or the string of the class name for comparison. This assertion will also pass for inheritance or a test for an interface.
assertRegex($value, $regex, [$msg]) Tests that $value passes the regular expression $regex.

Call Count Assertions

Call count assertions depend on a mock object to perform a check. Mock objects can be created with a call to $this→mock(). See the section on MockObjects for information on creating valid testable objects for these assertions.

In these calls, $params is an optional argument. If provided, calls will be matched against the parameter expectations passed in.

Some examples of the assertCallCount call

</code>
$this->assertCallCount($mocked_class, 'fooMethod', 3, array(new Snap_Anything_Expectation()))

$this->assertCallCount($mocked_class, 'fooMethod', 7);
*methodName($params, [$optional]) Description
assertCallCount($object, $method, $expected, [$params], [$msg]) Tests that $object→$method has been called $expected times.
assertMinimumCallCount($object, $method, $expected, $params, [$msg]) Tests that $object→$method has been called at least an $expected number of times.
assertMaximumCallCount($object, $method, $expected, $params, [$msg]) Tests that $object→$method has not been called more than $expected number of times.
Last edited by Jakobo, Sun Jul 19 16:25:03 -0700 2009
Home | Edit | New
Versions: