MicroUnit

Welcome to MicroUnits official documentation page

MicroUnit is a lightweight, expressive, and flexible unit testing framework for PHP.
It is designed to help you write clear, maintainable, and robust tests for your PHP projects with minimal setup and maximum power.

⚠️ MicroUnit is currently in public beta!
Features may change and bugs may exist. Feedback is welcome as we prepare for the first stable release.


Documentation Overview


Quick Start

  1. Install MicroUnit
    Add MicroUnit to your project using Composer:

    composer require your-vendor/microunit --dev
    
  2. Create your microunit.config.php
    Create microunit.config.php in your current working directory or any parent directories:

    Note: All paths are going to be resolved relative to the location of your config file.

    <?php
    use MicroUnit\Config\MicroUnitConfigBuilder;
    use MicroUnit\Output\MinimalStringTestWriter;
    
    return MicroUnitConfigBuilder::create()
        ->withTestDir('./tests')
        ->addTestFilePattern('*Test.php') // If not configured '*-tests.php' will be used
        ->addTestWriter(new MinimalStringTestWriter()) //If not configured MinimalStringTestWriter will be used
        ->build();
    
  3. Write your first test
    Create a test file in your specified test directory (or any child directory) and start testing.

    use MicroUnit\Assertion\Assert;
    use MicroUnit\Setup\TestSetup;
    
    $tester = TestSetup::getTester("YOUR_TEST_SUITE_NAME");
    $tester->define('my_first_test', function(){
         Assert::equals(2, 1 + 1);
    })
    
  4. Run Your Tests
    Use your preferred test runner or CLI integration.

    vendor/bin/microunit
    

Why MicroUnit?


More Resources


⬆ Back to Top