property-testing-core — framework-agnostic property-based testing engine with integrated shrinking
$ composer require --dev rasuvaeff/property-testing-core
$definition = new PropertyDefinition( id: 'demo::everyIntStaysBelowHundred', name: 'everyIntStaysBelowHundred', generators: ['value' => Gen::intBetween(0, 10_000)], parameterNames: ['value'], config: new PropertyConfig(runs: 200, seed: 42),); $result = (new PropertyRunner())->run($definition, new CallableTrialExecutor( static function (int $value): void { if ($value >= 100) { throw new RuntimeException(sprintf('%d is not below 100', $value)); } },));
A property-based testing engine with integrated shrinking, no test-framework dependency.
Hand-picked example inputs miss edge cases. The engine generates hundreds of random inputs, finds a failing one and shrinks it to a minimal, readable counterexample.
Gen facade: ints, floats, strings, bytes, naughtyString, mixed, arrays, records.PropertyRunner returns structured results. It never prints, exits or throws to report an outcome.FilesystemCorpus replays recorded failures before the random phase.flakyReplays times.Gen::rules).Assume, Classify distribution gates, targeted search, derandomized runs.Property falsified after 0 successful run(s); seed=42 Original: value=3989 Shrunk: value=100 (9 shrink step(s), 39 trial(s)) Changed: value=3989 -> 100 Failure: 100 is not below 100
Targeted search climbs a reported score to reach a corner that uniform sampling rarely hits.
static function (int $a, int $b, int $c): void { Target::maximize('sum', $a + $b + $c); Assert::true($a + $b + $c <= 2_900);0.17% of the space}
A rule-based state machine: rules are steps, a precondition guards one, an invariant holds after each.
final class QueueMachine{ private array $model = []; public function __construct(private readonly Queue $sut) {} #[Rule] public function enqueue(int $value): void { $this->sut->push($value); $this->model[] = $value; } #[Rule] #[Precondition('notEmpty')] public function dequeue(): void { Assert::same($this->sut->pop(), array_shift($this->model)); } public function notEmpty(): bool { return $this->model !== []; } #[Invariant] public function sizeMatches(): void { Assert::same($this->sut->size(), count($this->model)); }}
Gen::forClass builds a generator from the constructor's psalm annotations, with per-parameter overrides.
final readonly class Money{ /** * @param int<0, 1000> $amount * @param non-empty-string $label * @param list<int> $tags */ public function __construct( public int $amount, public string $label, public array $tags, public Currency $currency, ) {}} foreach (Gen::sample(Gen::forClass(Money::class), 3, 7) as $money) { printf(" amount=%d currency=%s\n", $money->amount, $money->currency->name);}$fixed = Gen::forClass(Money::class, ['amount' => Gen::intBetween(500, 510)]);
| Package | Role |
|---|---|
| property-testing-testo(3) | #[Property] for Testo |
| property-testing-phpunit(3) | Fluent forAll()->check() for PHPUnit |
| property-testing-openapi(3) | Requests generated from an OpenAPI document |
| property-testing-names(3) | Human-name generators |
Values come from MT19937 seeded by the reported seed: a PRNG, not a CSPRNG. Seeds are reproducibility handles, not secrets. The corpus persists failing inputs as plain JSON.
Requires PHP 8.3–8.5, ext-mbstring, ext-random, ext-tokenizer.
required by: property-testing-names(3), property-testing-openapi(3), property-testing-phpunit(3), property-testing-testo(3), schema(3)
First released as v0.1.0 on 2026-08-09; 22 releases in all.
| v1.3.0 | 2026-11-03 |
| v1.2.0 | 2026-10-02 |
| v1.1.0 | 2026-09-28 |
| v1.0.0 | 2026-09-20 |
| v0.12.0 | 2026-09-20 |
| v0.11.0 | 2026-09-19 |
| v0.10.0 | 2026-09-12 |
| v0.9.0 | 2026-09-05 |
| v0.8.0 | 2026-09-04 |
| v0.7.0 | 2026-09-04 |
… and 12 earlier. All releases
/ search · n N next, previous · g G top, bottom · q back to the index