title | description |
---|---|
Assertions |
Assertions |
By now you've caught a glimpse of some available assertions. They are the ones that actually perform the checks to ensure that things are going as planned.
Remember, the $this
variable inside the given
closure in tests is always bound to a Test Case class. Therefore
assertions are methods of the $this
variable.
it('asserts true is true', function () {
$this->assertTrue(true);
});
For the full list of assertions, please refer to PHPUnit Assertions documentation.
The assertTrue
asserts the given value is truthy.
$this->assertTrue(true);
The assertFalse
asserts the given value is falsy.
$this->assertFalse(false);
The assertCount
asserts the given iterable to contain the same number of items.
$array = [1, 2, 3, 4];
$this->assertCount(4, $array);
The assertEquals
asserts the given values are equal.
$array = [1, 2, 3, 4];
$this->assertEquals([1, 2, 3, 4], $array);
The assertEmpty
asserts the given iterable is empty.
$array = [];
$this->assertEmpty($array);
The assertStringContainsString
asserts the given string exists.
$this->assertStringContainsString('Star', 'Star Wars');
Next section: Expectations →