PHPUnit_Assert

PHPUnit_Assert --  Provides the assert*()-functions

Using

You should never get in contact with this class. PHPUnit_Assert is inherited by PHPUnit_TestCase and you can call the assert*()-functions in your test class through $this

If you go through the assert*() documentation you will note, that sometimes an assertation can expressed with more then one assert-function, ie:
...
$expected = "abc";
$result = myFunction(...); // returns "abc"
// [1]
$this->assertEquals($expected,$result);

// or [2]
$this->assertTrue($expected == $result);
Both versions are correct, but the first is strictly recommended. You want to test a function returning the expected string and not if the '==' operator works correctly. And the first version more self-descriptive.

PHPUnit_Assert::assertEquals

void assertEquals (mixed $expected, mixed $result [, string $message = '' [, mixed $delta = 0]])

Parameter

Fails

Fails if the expected and the result value are not equal.

Note

With the delta value you can compare two values which are only nearly equal, ie.: 5 is equal 5.04 depending on the situation. This is a tribute to Java background of the test framework, which is also used in scientific enviroments. For a physicist a difference of 10% between the expected and result value must not be a difference, such values are 'equal' for them. ;-)

PHPUnit_Assert::assertNotNull

void assertNotNull (object $expected, string $message)

Parameter

Fail

Fails if the object is null.

PHPUnit_Assert::assertNull

void assertNull (object $expected, string $message)

Parameter

Fail

Fails if the object is not null.

PHPUnit_Assert::assertTrue

void assertTrue (boolean $condition, string $message)

Parameter

Fail

Fails if the condition returns false.

Note

AssertTrue() is a more general assert function. You should first check, if there is not a better assertion function, This can avoid problems implementating a test case..