hoa/realdom
Hoa\Realdom models sets of possible values as domains—booleans, numbers, strings, arrays and more—and samples them randomly with constraints and composition. Useful for property-based testing and generating realistic test data in PHP.
hoa/realdom is a grammar-driven sampler: you hand it a grammar (the Hoa LL(k) dialect used by hoa/compiler) and it emits random-but-structurally-valid documents. It was the generation half of Hoa's testing toolchain. It is archived (last tag 1.17.01.13, 2017-01-13), has 7 stars, zero dependents — treat the decision to install it as "I am adopting this code," not "I am consuming a dependency."
php:7.1-cli) or a dev-only image, with its own composer.json.composer require hoa/realdom
composer lock # commit it; nothing upstream will ever fix a break
require 'vendor/autoload.php'; usually suffices, but older Hoa tags rely on hoa/consistency's own autoloader rather than a PSR-4 map. If Hoa\Realdom\* is not found, check that Hoa\Consistency\Autoloader is registered before blaming your app's autoload config.README.md (short, example-driven) → Hoa/Realdom/Realdom.php (the entire public surface) → the sampler/visitor classes (where the generation actually happens) → Test/Unit/ (the only guaranteed-working usage examples) → hoa/compiler's bundled grammar resources for a known-good grammar to feed it.require 'vendor/autoload.php';
// Copy the constructor call verbatim from the README of the tag you installed —
// the signature drifted between releases and there is no API doc to fall back on.
$realdom = new Hoa\Realdom\Realdom(/* grammar, see Test/Unit for a working argument */);
for ($i = 0; $i < 100; ++$i) {
file_put_contents(__DIR__ . "/fixtures/case-$i.xml", $realdom->generate());
}
If that snippet doesn't run in ten minutes, stop — the package has not earned more of your day than that.
Data-provider generator. The highest-leverage integration is a thin factory that returns N samples into a PHPUnit data provider or an atoum dataset. Keep the factory in your own namespace so tests never import Hoa classes directly.
Single source of truth for the grammar. Feed Realdom the same grammar your parser is compiled from. Generated documents are then syntactically valid by construction, so any failure is a real bug in the consumer — this is the one thing Realdom does that Faker cannot.
Generate → validate loop. Realdom guarantees structure, not semantics. Pair it with a schema validator (libxml/XSD, respect/validation) to catch business-rule bugs, and let the sampler find the structural edges.
Snapshot mode for CI. A random generator in CI means flaky red builds on the day upstream disappears. Run generation once on a developer machine, commit the corpus, and point CI at the fixtures. Keep a --regenerate switch for deliberate churn.
Seed everything. The sampler draws from PHP's global RNG. Call mt_srand($seed) (and srand($seed)) before the first generate() and expose the seed in your test command so failures are reproducible.
Adapter behind an interface. Wrap it:
interface SampleGenerator { public function generate(int $n): iterable; }
You will want to swap it for Faker, eris/eris, or hand-written fixtures eventually — make that a one-file change.
Batch/console command. A small Artisan or Symfony command (xml:sample --count=500 --out=fuzz/) is the natural day-to-day entry point; nobody should be calling the library from controllers.
hoa/compiler, hoa/stream, and hoa/consistency. Isolate it as a dev tool with its own lockfile rather than resolving it in the main graph.app/Support/ (or a private package), strip the hoa:// stream-wrapper dependency, and own it explicitly.max_execution_time, and abort a batch after N seconds rather than debugging a stuck process.hoa:// URIs only resolve after bootstrap. hoa://Library/... paths fail if you require files manually or reorder the bootstrap. Let the consistency autoloader come up first.Hoa\Compiler before assuming Realdom is at fault — usually the grammar is.fakerphp/faker; for property-based testing, use eris/eris; for schema checks, respect/validation. Realdom's only defensible niche is "many structurally valid documents from one grammar," and that niche is small enough that most teams should reach for it exactly once, evaluate for an hour, and move on.How can I help you explore Laravel packages today?