Show Menu
Cheatography

PHPUnit Cheat Sheet - Basics Cheat Sheet (DRAFT) by

The most useful assertions and annotations of PHPUnit

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

Instal­lation

composer global require "­php­uni­t/p­hpu­nit­=4.8.*­"
php phpuni­t{.p­har} --version

Command Line - Test selection options

--filter <pa­tte­rn>
Filter which tests to run.
--group ...
Only runs tests from the specified group(s).
--excl­ude­-group ...
Exclude tests from the specified group(s).
--list­-groups
List available test groups.
-c <co­nfi­gur­ati­on_­fil­e>
Use config­uration file to find testsuites

Command Line - Execution options

--stop­-on­-error
Stop execution upon first error.
--stop­-on­-fa­ilure
Stop execution upon first error or failure.
--verbose
Output more verbose inform­ation.
--debug
Display debugging inform­ation during test execution.
--help
Display usage inform­ation.
 

Common assertions

assert­{No­t}E­quals($a, $b), assert­{No­t}Same($a, $b)
assertTrue($a), assert­False($a), $asser­t{N­ot}Null($a)

Type / Class assertions

assert­{No­t}I­nte­rna­lType($expe­cte­dType, $a)
assert­{No­t}I­nst­anceOf($expe­cte­dClass, $a)
assert­Obj­ect­{No­t}H­asA­ttr­ibute($attr­ibute, $a)