Get Started
Unitary is an evidence-based testing framework for practical PHP development. Each test is a set of validations that describe and confirm how your code behaves in real conditions
Install Unitary
Local installation (recommended)
Add Unitary as a development dependency:
composer require --dev maplephp/unitary
Run it using the local binary:
php vendor/bin/unitary
Global installation
To use Unitary in any project:
composer global require maplephp/unitary
Ensure Composer’s global bin path is in your system PATH
Now you can run:
unitary
Local gives consistency, global gives convenience. For most projects a local installation is best as it keeps Unitary tied to your code and version control.
1. Create your first test
Unitary automatically finds any PHP file starting with unitary- in your project (excluding vendor directory). This behavior can be changed by adding a config file.
Note that all your project files are already autoloaded through Composer, so you can use any of your classes directly in tests, no manual includes or setup required.
Create a file named:
tests/unitary-user.php
Example test
use MaplePHP\Unitary\{Expect,TestCase};
group("Your grouped test subject", function (TestCase $case) {
$json = '{"response":{"status":200,"message":"ok"}}';
$case->expect($json)
->isJson()
->hasJsonValueAt("response.status", 200)
->validate();
});
You can also get a ready-to-use boilerplate code with:
php vendor/bin/unitary template
2. Run your tests
Execute all discovered test groups:
php vendor/bin/unitary
Show only failed validations:
php vendor/bin/unitary --errors-only
For help and all CLI options:
php vendor/bin/unitary --help
No configuration needed
Configuration
You don’t need to configure anything to start testing, Unitary runs the moment it’s installed. It automatically discovers your test files, autoloads your project through Composer and prints clear validation results without any complicated setup.
When you want to customize its behavior, you can do this through the CLI or by adding a configuration file.
Add a optional Composer script
In your composer.json:
"scripts": {
"test": "php vendor/bin/unitary"
}
Run with:
composer test
Pass additional arguments using --:
composer test -- --help