Runnable scripts demonstrating rasuvaeff/property-testing-core.
| Script | Shows | Needs server? |
|---|---|---|
basic.php |
A property that holds, one that is falsified, and how the counterexample is shrunk by descending the Shrinkable tree (uses generators directly, no runner) |
No |
generators.php |
sample, boundary bias, uuid, datetime, dictOf, record, and dependent generation with flatMap (uses generators directly, no runner) |
No |
standalone_runner.php |
Driving the framework-agnostic engine directly: a hand-built PropertyDefinition, CallableTrialExecutor, structured PropertyResult inspection, and the run knobs — ShrinkMode::Off reporting a counterexample as generated, path replaying a recorded descent (and refusing a stale one), the DistributionReport a listener reads off PropertyFinished, and phases: [Phase::Examples, Phase::Corpus] as a fast gate that never reaches the random phase |
No |
for_class.php |
Gen::forClass(): the same shape with and without psalm annotations, an override narrowing one parameter, and a validating constructor both ways (throwing by default, skipInvalid: true discarding) |
No |
swarm.php |
Swarm testing: how often a case avoids an operation entirely with a uniform alphabet versus a per-case subset, Gen::swarm() over a choice generator and over Gen::commands(), and a shrink descent that stays inside the subset it came from |
No |
targeted_search.php |
Targeted search: a corner bug (three parameters whose sum exceeds a threshold 0.17% of the space reaches) missed by 300 random runs and found by 200 random plus 100 search runs climbing Target::maximize('sum', …); a listener narrates every TargetImproved |
No |
rule_machine.php |
The rule-based stateful façade: a StackMachine with #[Rule] steps, a #[Precondition] guard and an #[Invariant], run through Gen::rules() against a correct stack (passes) and a FIFO one (falsified, shrunk to [push(value: 0), push(value: 1), pop()]) |
No |
custom_listeners.php |
Custom observers over the engine's event model: a console reporter narrating the shrink descent and a telemetry collector aggregating run counts, timings and labels — pure PropertyListener implementations, no engine changes |
No |
case-studies/regex-anchor.php |
Docs cookbook case study: a $-anchored identifier validator accepting a trailing newline (ER-001) |
No |
case-studies/saturating-minus.php |
Docs cookbook case study: subtraction producing a negative duration instead of saturating at zero | No |
case-studies/backoff-cap.php |
Docs cookbook case study: jitter added after the cap was applied, pushing the delay past it | No |
case-studies/hash-bucketing.php |
Docs cookbook case study: a rollout hash salted with the percentage, breaking monotonicity across percentage changes | No |
case-studies/faker-vs-property.php |
Docs cookbook comparison: the same UTF-8 truncation bug found with realistic (Faker-shaped) data and with shrinkable data — both falsify, only one minimises | No |
case-studies/ backs the documentation site's Cookbook
— each script's buggy code is reconstructed inline from a real incident
(never imported from the package it originally happened in) and pinned to a
fixed seed, so the counterexample quoted on the corresponding page stays
reproducible.
The examples are plain PHP scripts that load the package via Composer autoload.
Run them from the package root after composer install:
docker run --rm -v "$PWD":/app -w /app composer:2 php examples/basic.php