An object oriented approach to testing for PHP.

0.2.1 2017-10-13 12:15 UTC


An object oriented approach to testing PHP code.

Tester aims to be: easy to learn, light weight, object oriented, and extendable.

Documentation here


The library is released as a composer package.

composer require --dev thomasnordahldk/tester


Tests are defined by creating TestCase classes.

class MyTestCase implements TestCase
    public function getDescription(): string
        return "My new unit test";
    public function run(Tester $tester): void
        $tester->assert(true, "This assertion passes!");
        $tester->assert(false, "This assertion fails!");

The test case is defined as a description of the test and a run test method.

Docs: Creating a test case.

Test suites

Tests suites are defined by the TestSuite class which is created with a description and an array of TestCase classes.

$unit_tests = new TestSuite("Unit tests", [new UserUnitTest, AddressUnitTest]);

Docs: Test Suites.

Running tests

The library comes with a native test runner that is run from the command line interface, and outputs a summary of the test.

Which tests to run is defined in the file test.php in the root composer directory. The file is expected to return an array of test suites.

# test.php
$unit_tests = new TestSuite("Unit tests", [new UserUnitTest, new AddressUnitTest]);

return [$unit_tests];
$composer-root/~ bin/tester
Unit tests (test cases: 2)

 - Unit test of User
 - Unit test of Address

Success! 2 tests, 8 assertions (0.03s)

For a comprehensive description of the options available for the native test runner script:

Docs: How to run tests.


This library is inspired by the testing library mindplay-dk/testies.