Cheatography
https://cheatography.com
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 Introduction
Description |
PHPUnit is a programmer-oriented 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 phpunit/phpunit ^10
|
Check your PHPUnit Version $ ./vendor/bin/phpunit --version
|
Run PHPUnit Tests $./vendor/bin/phpunit tests
|
PHPUnit String Format Placeholders
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 characters. |
%i |
A signed integer value |
%d |
An unsigned integer value |
%x |
One or more hexadecimal character. |
%f |
A floating point number |
%c |
Any single character |
%% |
A literal percent character |
Basic Tests
|
(bool $condition[, string $message = ''])
|
|
(bool $condition[, string $message = ''])
|
|
(bool $condition[, string $message = ''])
|
|
(bool $condition[, string $message = ''])
|
|
(mixed $actual[, string $message = ''])
|
|
(mixed $actual[, string $message = ''])
|
|
|
Numeric Tests
|
(mixed $expected, mixed $actual[, string $message = ''])
|
assertGreaterThanOrEqual
|
(mixed $expected, mixed $actual[, string $message = ''])
|
|
(mixed $expected, mixed $actual[, string $message = ''])
|
assertLessThanOrEqual
|
(mixed $expected, mixed $actual[, string $message = ''])
|
|