Unitary is a PHP 8.2+ testing framework with a standalone CLI, fluent expectations, built-in test doubles, JUnit reporting and optional Xdebug line coverage. Install it with Composer and create a unitary-*.php file to run your first test.
Visit the full documentation at:
👉 https://maplephp.github.io/unitary/
Unitary is designed to feel natural for developers. With clear syntax, built-in validation, and zero setup required, writing tests becomes a smooth part of your daily flow and not a separate chore.
use MaplePHP\Unitary\TestCase;
group("Your grouped test subject", function (TestCase $case) {
$json = '{"response":{"status":200,"message":"ok"}}';
$case->expect($json)
->isJson()
->hasJsonValueAt("response.status", 200)
->validate();
});Set up your first test in three easy steps:
composer require --dev maplephp/unitaryYou can run unitary globally if preferred with composer global require maplephp/unitary.
Create a file like tests/unitary-request.php. Unitary automatically scans all files prefixed with unitary- (excluding vendor/).
Paste this test boilerplate to get started:
use MaplePHP\Http\Request;
use MaplePHP\Unitary\TestCase;
group("HTTP Request", function(TestCase $case) {
$request = new Request("GET", "https://example.com/?id=1&slug=hello");
$case->expect($request->getUri()->getQuery())
->hasQueryParam("id", 1)
->hasQueryParam("slug", "hello")
->validate();
});💡 Tip: Run
php vendor/bin/unitary templateto print a test template.
php vendor/bin/unitaryUse --path=tests/ to scan a directory or --path=tests/ExampleSpec.php to run a single PHP file.
Use --discover-pattern='*Spec.php' to match filenames, --discover-pattern='tests/*Spec.php'
to match paths relative to the directory being scanned, or --discover-pattern='tests/' to
find PHP files in directories named tests at any depth. --exclude='legacy/,archive'
excludes those paths relative to the directory being scanned. Directory scans skip vendor/ and registered Composer dependency directories.
With --smart-search, a PHP file that matches the discovery pattern runs on its own. Other
files start the search in their containing directory. If a directory yields no tests, Unitary
tries its parents up to the nearest directory containing composer.json or unitary.config.php,
using the working directory as the boundary when neither file exists.
php vendor/bin/unitary --help
With that, you are ready to create your own tests!
v2.0.0 This release marks Unitary’s transition from a testing utility to a full framework. With the core in place, expect rapid improvements in upcoming versions.
Unitary stands on a solid foundation of years of groundwork. Before Unitary was possible, these independent components were developed:
maplephp/Emitron– PSR-15 kernel and middleware enginemaplephp/http– PSR-7 HTTP messaging and stream handlingmaplephp/prompts– Interactive prompt/command enginemaplephp/blunder– A pretty error handling frameworkmaplephp/validate– Type-safe input validationmaplephp/dto– Strong data transportmaplephp/container– PSR-11 Container, container and DI systemmaplephp/cache– PSR-6 and PSR-16 caching library
This full control means everything works together, no patching, no adapters and no guesswork.
Test everything. All the time. Without friction.
Run a focused group while editing and the full suite before integrating changes.
That’s DarkBark. Dark, quiet, confident, like a rainy-night synthwave playlist for your CLI.
Unitary is still young — your bug reports, feedback, and suggestions are hugely appreciated.
If you like what you see, consider:
- Reporting issues
- Sharing feedback
- Submitting PRs
- Starring the repo ⭐
Follow the full suite of MaplePHP tools:
