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.
Assertions
Learn about all assertion methods, including static and chainable usage.
Configuration
Discover all configuration options and how to customize your test environment.
Mocking
Explore the mocking engine for creating and verifying test doubles.
Output
See how to configure and extend test output writers.
Usage
Get started with defining, grouping, and running tests.
Logging
Learn more about the logging system in microunit, how it works, where your logs are, etc.
Toolkit
Explore helpful tools designed to simplify common testing tasks and enhance code readability.
Troubleshooting
Are you having trouble with running your tests? Check out this section where the usual pitfalls and errors are documented and how to overcome them.
Install MicroUnit
Add MicroUnit to your project using Composer:
composer require your-vendor/microunit --dev
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();
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);
})
Run Your Tests
Use your preferred test runner or CLI integration.
vendor/bin/microunit