PHPUnit – Get Started Writing Tests With Assertions

PHPUnit is a unit testing framework for the PHP programming language. PHPUnit was created by Sebastian Bergmann and its development is hosted on GitHub.

PHPUnit is currently the most popular PHP unit testing framework. Besides providing features such as mocking objects, it provides code coverage analysis, logging and tons of other powerful features.

PHPUnit Installation

You can download a PHP Archive (PHAR) file that has all required dependencies of PHPUnit 8.5 bundled in a single file:

Alternatively, you may use Composer to download and install PHPUnit as well as its dependencies.

PHPUnit Assertions

Here are a list of all PHPUnit assertions that come with PHPunit.

Arrays

Booleans

Classes / Objects

Comparison

Files

JSON

Strings

XML

  • assertEqualXMLStructure()
  • assertXmlFileEqualsXmlFile()
  • assertXmlStringEqualsXmlFile()
  • assertXmlStringEqualsXmlString()

Mixed / Misc

Hopefully this simple tutorial helped you with your development.