PHPUnit Testing Framework

Overview

Qualified supports the PHPUnit testing framework:

  • PHPUnit 5 (PHP 7.0)
  • PHPUnit 9 (PHP 7.4)
  • PHPUnit 9.5 (PHP 8)

PHPUnit Quick Start

All tests start with a subclass of TestCase. You can then add one or more test case methods to that class, each of which must be public and start with test. The name of the test class must end with Test.

Assertions

Use $this->assert* methods to create your assertions, such as $this->assertSame(actual, expected, [message]).

Warning

assertEquals and similar *Equals methods have surprising type coercion, so 42 and true would be considered equal. Prefer assertSame, assertObjectEquals, assertTrue or type-check arguments before calling assertEquals.

Basic Example

<?php
use PHPUnit\Framework\TestCase;

class TwoOldestAgesTest extends TestCase {
    public function testSolution() {
        $actual = twoOldestAges([6, 5, 83, 5, 3, 18]);
        $expected = [83, 18];
        $this->assertSame($expected, $actual);
    }
}

Learn More

You can learn more on the PHPUnit website.