Show Menu
Cheatography

PHPUnit 10 Assertions Cheat Sheet (DRAFT) by

A cheat sheet for the assertions in PHPUnit 10.

This is a draft cheat sheet. It is a work in progress and is not finished yet.

PHPUnit Introd­uction

Descri­ption
PHPUnit is a progra­mme­r-o­riented testing framework for PHP.
Homepage
Docs

PHPUnit 10 Example Test

<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;

final class exampleTest extends TestCase
{
    public function testBasicExample(): void
    {
        $this->assertTrue(true);
    }
}

PHPUnit 10 Composer Commands

Include PHPUnit 10 With Composer
$ composer require --dev phpuni­t/p­hpunit ^10
Check your PHPUnit Version
$ ./vend­or/­bin­/ph­punit --version
Run PHPUnit Tests
$./vendor/bin/phpunit tests

PHPUnit String Format Placeh­olders

Placeholder
Meaning
%e
Directory separator
%s
One or more of anything except end of line
%S
Zero or more of anything except end of line
%a
One or more of anything including end of line
%A
Zero or more of anything including end of line
%w
Zero or more white space charac­ters.
%i
A signed integer value
%d
An unsigned integer value
%x
One or more hexade­cimal character.
%f
A floating point number
%c
Any single character
%%
A literal percent character

Basic Tests

assertTrue
(bool $condi­tion[, string $message = ''])
assertNotTrue
(bool $condi­tion[, string $message = ''])
assertFalse
(bool $condi­tion[, string $message = ''])
assertNotFalse
(bool $condi­tion[, string $message = ''])
assertEmpty
(mixed $actual[, string $message = ''])
assertNotEmpty
(mixed $actual[, string $message = ''])
 

Numeric Tests

assert­Gre­ate­rThan
(mixed $expected, mixed $actual[, string $message = ''])
assert­Gre­ate­rTh­anO­rEqual
(mixed $expected, mixed $actual[, string $message = ''])
assert­Les­sThan
(mixed $expected, mixed $actual[, string $message = ''])
assert­Les­sTh­anO­rEqual
(mixed $expected, mixed $actual[, string $message = ''])