Skip to content

Latest commit

 

History

History
106 lines (72 loc) · 2.12 KB

assertions.md

File metadata and controls

106 lines (72 loc) · 2.12 KB
title description
Assertions
Assertions

Assertions

Overview

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);
});

Available Assertions

For the full list of assertions, please refer to PHPUnit Assertions documentation.

assertTrue()

The assertTrue asserts the given value is truthy.

$this->assertTrue(true);

assertFalse()

The assertFalse asserts the given value is falsy.

$this->assertFalse(false);

assertCount()

The assertCount asserts the given iterable to contain the same number of items.

$array = [1, 2, 3, 4];

$this->assertCount(4, $array);

assertEquals()

The assertEquals asserts the given values are equal.

$array = [1, 2, 3, 4];

$this->assertEquals([1, 2, 3, 4], $array);

assertEmpty()

The assertEmpty asserts the given iterable is empty.

$array = [];

$this->assertEmpty($array);

assertStringContainsString()

The assertStringContainsString asserts the given string exists.

$this->assertStringContainsString('Star', 'Star Wars');

Next section: Expectations →