Skip to content
maplephpPublic

About

Unitary is a modern PHP testing framework for developers who value speed, precision, and full control.

Topics

Resources

Code of conduct

Contributing

Stars

5 stars

Watchers

1 watching

Forks

Latest commit

 

History

210 Commits

Folders and files

Repository files navigation

Unitary – Evidence-Driven PHP Testing Framework

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.

Prompt demo


Documentation

Visit the full documentation at:
👉 https://maplephp.github.io/unitary/


Familiar Syntax. Fast Feedback.

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();
});

Getting Started (Under 1 Minute)

Set up your first test in three easy steps:

1. Install

composer require --dev maplephp/unitary

You can run unitary globally if preferred with composer global require maplephp/unitary.


2. Create a Test File

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 template to print a test template.


3. Run Tests

php vendor/bin/unitary

Use --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.

Need help?

php vendor/bin/unitary --help

The Output:

Prompt demo And that is it! Your tests have been successfully executed!

With that, you are ready to create your own tests!


📅 Version 2

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.


🧱 Built From the Ground Up

Unitary stands on a solid foundation of years of groundwork. Before Unitary was possible, these independent components were developed:

This full control means everything works together, no patching, no adapters and no guesswork.


Philosophy

Test everything. All the time. Without friction.

Run a focused group while editing and the full suite before integrating changes.


Like The CLI Theme?

That’s DarkBark. Dark, quiet, confident, like a rainy-night synthwave playlist for your CLI.

Download it here


🤝 Contribute

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 ⭐

📬 Stay in Touch

Follow the full suite of MaplePHP tools:

About

Unitary is a modern PHP testing framework for developers who value speed, precision, and full control.

Topics

Resources

Code of conduct

Contributing

Stars

5 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages