Testing: Assertions
Introduction
Mantle's Test Case provides some assertions above and beyond PHPUnit's, largely
influenced by WP_UnitTestCase. Here's a run-through:
assertWPError and assertNotWPError
Assert the given item is/is not a WP_Error:
$this->assertWPError( $actual, $message = '' );
$this->assertNotWPError( $actual, $message = '' );
General Assertions
assertEqualFields
Asserts that the given fields are present in the given object:
$this->assertEqualFields( $object, $fields );
assertDiscardWhitespace
Asserts that two values are equal, with whitespace differences discarded:
$this->assertDiscardWhitespace( $expected, $actual );
assertEqualsIgnoreEOL
Asserts that two values are equal, with EOL differences discarded:
$this->assertEqualsIgnoreEOL( $expected, $actual );
assertEqualSets
Asserts that the contents of two un-keyed, single arrays are equal, without accounting for the order of elements:
$this->assertEqualSets( $expected, $actual );
assertEqualSetsWithIndex
Asserts that the contents of two keyed, single arrays are equal, without accounting for the order of elements:
$this->assertEqualSetsWithIndex( $expected, $actual );
assertNonEmptyMultidimensionalArray
Asserts that the given variable is a multidimensional array, and that all arrays are non-empty:
$this->assertNonEmptyMultidimensionalArray( $array );
WordPress Query Assertions
assertQueryTrue
Assert that the global WordPress query is true for a given set of properties and false for the rest:
$this->assertQueryTrue( ...$prop );
assertQueriedObjectId
Assert that the global queried object ID is equal to the given ID:
$this->assertQueriedObjectId( int $id );