dave1010 / it-should
IT: Inline Test for PHP
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/dave1010/it-should
Requires
- php: ^8.4
- composer-runtime-api: ^2.2
This package is auto-updated.
Last update: 2025-11-21 17:45:54 UTC
README
IT: Inline Test for PHP, designed for PHP 8 5.
Install
composer require --dev dave1010/it-should
Usage
Console command
Run inline tests under one or more files/directories:
./vendor/bin/it src
Run ./vendor/bin/it help for available options.
Writing tests
Write tests inline on functions and methods with the \IT\Should annotation.
#[\IT\Should(return: 4, given: [2, 2])] function add(int $a, int $b): int { return $a + $b; }
Use the given parameter to pass the arguments that should be provided to your function or method
when executing the inline test.
For methods, IT will instantiate a new object when the method is non-static (without handling constructor arguments). You can
override this by providing a callable in the optional with parameter to create the system under test:
class Incrementer { public function __construct(private int $step) { } #[\IT\Should(return: 2, given: [1], with: static function () { return new Incrementer(1); })] public function add(int $value): int { return $value + $this->step; } }
Any callable is accepted here, whether a static closure (possible in PHP 8.5 attributes) or a class factory method.
Running tests
./vendor/bin/it src
IT will look at all the functions and classes/methods in src that have the \IT\Should
attributes, then call each one, checking the output is as expected.
Development
For contributors working on this repository, the console command lives at bin/it, Not in vendor.
Run composer install after cloning to generate the local vendor/autoload.php so
bin/it and the bundled examples work without additional setup.
The examples and CI workflow currently run against PHP 8.5; you can mirror this locally with:
php bin/it examples
Architecture
Main interfaces:
- Locator (finds inline tests in code, via reflection).
- Executor (runs the tests and captures results).
- Comparator (compares actual vs expected, producing human-friendly diffs).
- Reporter (outputs results, exit with non-zero if any failure).