MicroUnit is a PHP testing framework that doesn't pull in a single Composer package, and it just reached 1.0 after six betas. You write each test as a closure with a name that says what it checks, so there's no base TestCase class to extend. Mocks, snapshots, parallel runs, and code coverage all come in the same package. It requires PHP 8.5 or newer.

MicroUnit doesn't depend on any framework. It also ships integrations for Laravel, Symfony, and CodeIgniter.

Some of the features include:

  • Sixty assertions, static or fluent, including partial matches (containsSubset), any-order comparisons (equivalent), soft assertions (multiple), and eventually
  • Mocks, stubs, and spies with per-instance call logs, without a second library
  • Snapshots that MicroUnit never creates by accident in CI
  • Parallel runs with --parallel, which keeps each suite together in one worker
  • A Test Explorer, opened with microunit explorer, that shows your suite live in the browser and lets you run one test, a suite, or only the failures
  • Integration testing helpers: fixtures with cleanup, a database helper, and an HTTP server and client
  • Reports in JUnit, HTML, GitHub Actions annotations, log files, and JSON, several at once
  • Framework integrations that let you call Laravel's, Symfony's, or CodeIgniter's own testing helpers inside MicroUnit tests

Writing a Test

Here's a test file from the README:

use MicroUnit\Assertion\Assert;
use MicroUnit\Setup\TestSetup;

$tester = TestSetup::getTester('Cart');

$tester->fixture('cart', fn() => new Cart());

$tester->define('adds_items_and_totals_them', function (Cart $cart): void {
    $cart->add(new Item('Keyboard', 4900));
    $cart->add(new Item('Mouse', 1900));

    Assert::countEquals(2, $cart->items());
    Assert::exact(6800, $cart->total());
});

$tester->defineGroup('applies_discounts', function (int $percent, int $total): void {
    Assert::exact($total, new Cart(10000)->withDiscount($percent)->total());
}, [
    'none' => [0, 10000],
    'a quarter' => [25, 7500],
]);

getTester('Cart') creates a suite called Cart. The fixture builds a new Cart, and MicroUnit passes it to any test with a parameter named $cart. defineGroup() runs the closure once per data set, so you get two tests, applies_discounts_none and applies_discounts_a quarter. Assertions take the expected value first and the actual value second, the same order PHPUnit uses.

You can also start from the value and chain checks, as in AssertArray::begin($ids)->isList()->isUnique()->countEquals(3). You can mix both styles in one test.

You don't need a config file if your tests live in tests/ and their file names end in -tests.php. When you need more, the options go in one microunit.config.php file, written in plain PHP, so your editor can autocomplete them.

Benchmarks Against PHPUnit

The project measured MicroUnit 1.0 against PHPUnit on the test suites of six open-source projects, and against ParaTest for parallel runs. MicroUnit was faster in all 24 comparisons (four scenarios on six projects). The median speedups were 2.05x for a full suite, 2.62x for re-running one test file, 2.91x for a parallel run, and 2.93x for startup.

Here are the full suite results:

Project Tests PHPUnit MicroUnit Speedup
brick/math 24,782 3.74 s 0.77 s 4.87x
nesbot/carbon 6,233 40.4 s 35.9 s 1.13x
webmozart/assert 4,942 0.80 s 0.16 s 5.14x
league/commonmark 4,340 1.92 s 0.82 s 2.36x
symfony/yaml 1,427 1.64 s 0.94 s 1.74x
monolog/monolog 1,197 9.31 s 9.00 s 1.03x

The biggest gains are on suites with thousands of small tests, where the runner's own cost per test makes up most of the time. Carbon and Monolog spend most of their time inside the tests themselves. About 8 of Monolog's 9 seconds come from tests that wait on timeouts on purpose.

MicroUnit used less memory on five of the six projects. Carbon used 37% more. The benchmark page says this comes from microunit migrate, which copies inherited test methods into every subclass.

These are the project's own numbers. It ran them on November 19, 2026, on PHP 8.6.0 with OPcache off, on an Intel Core i7-1355U laptop running Windows 11. Each time is the median of five runs. The benchmarks page lists every excluded test with its reason. The harness is in the repo if you want to reproduce the results.

Test speed during the edit-and-rerun loop also comes up on the PHPUnit side. PHPUnit TIA runs only the tests your changes affect.

Code Coverage Without Xdebug or PCOV

MicroUnit measures coverage in plain PHP, so you don't need to install an extension or change php.ini. When coverage is on, MicroUnit registers a stream wrapper for file://. It then uses PHP's tokenizer to add a hit counter in front of each statement in the files you include. Line numbers stay the same as in the original file, so stack traces still point at the right lines.

Add --coverage to a run, or configure it:

use MicroUnit\Config\MicroUnitConfigBuilder;

return MicroUnitConfigBuilder::create()
    ->withTestDir('tests')
    ->withCoverage(
        include: 'src',
        html: 'build/coverage',
        clover: 'build/clover.xml',
        minimum: 80,
    )
    ->build();

This config measures src/, writes an HTML report and a Clover XML file, and fails the run when line coverage drops below 80%. Cobertura XML and a console table are also available.

The coverage docs list the limits. MicroUnit measures line coverage only, with no branch or path coverage. It needs the tokenizer extension, which some minimal Docker images leave out. With opcache.enable_cli=1, OPcache can serve cached bytecode and skip the counters, and MicroUnit prints a warning when that happens. Coverage runs are also slower than plain runs.

Migrating From PHPUnit

If you already have a PHPUnit suite, one command converts it:

vendor/bin/microunit migrate

The command writes the converted tests to tests-microunit/ and doesn't touch your originals, so you can run both suites side by side. It converts assertions, properties set in setUp() (which become fixtures), lifecycle hooks, data providers, expected exceptions, and PHPUnit mocks. It also writes a microunit.config.php from your phpunit.xml.

Some tests can't be converted, such as ones that use #[Depends] or #[RunInSeparateProcess]. Those become skipped tests that keep the original code and the reason. migration-report.json lists every one of them.

Plain PHP projects can remove PHPUnit at the end. Projects that use the Laravel, Symfony, or CodeIgniter integration keep phpunit/phpunit installed, because those frameworks build their test case classes on it.

AI Coding Agents and How the Project Is Built

In an agent session, MicroUnit prints one compact JSON object that lists only the failures, with the file and line, the expected and actual values, and the code around the failing line. It switches to this mode when CLAUDECODE=1 or MICROUNIT_AGENT=1 is set.

You can also turn on an opt-in integrity check that compares your test files with a git revision. It flags removed assertions, changed expected values, new skips, and deleted tests, which are the changes an agent might make to turn a red test green. vendor/bin/microunit init --skill installs a skill file that shows your agent how to write MicroUnit tests.

The maintainer writes MicroUnit itself with AI and reviews each change. The quality with AI page explains the checks. CI runs the suite 12 times on every push and pull request: on Ubuntu, Windows, and macOS, on PHP 8.5 and 8.6, once sequentially and once in parallel. CI also runs PHPStan at level max with no baseline, a 47% coverage floor, and the integrity check. Before each release, MicroUnit runs the converted test suites of the same six projects used in the benchmarks.

How to Install It

MicroUnit requires PHP 8.5 or newer and is tested on 8.5 and 8.6. Install it as a dev dependency:

composer require --dev microunit/microunit
vendor/bin/microunit init
vendor/bin/microunit

init writes a config file and a first test, set up for Laravel, Symfony, or CodeIgniter if it finds one in your project. MicroUnit is released under the Apache 2.0 license.

Visit the MicroUnit repo on GitHub and the 1.0 release notes for the full details. The package is microunit/microunit on Packagist.