giorgiosironi/eris
Eris brings QuickCheck-style property-based testing to PHP and PHPUnit. Define properties, generate many randomized inputs, and let Eris shrink failing cases to minimal counterexamples. Works with PHP 8.1+ and PHPUnit 10–13 via a simple TestTrait.
Model::factory() for generating complex, randomized test data (e.g., nested relationships, edge-case timestamps).success field").TestTrait and Generators classes require only:
use Eris\TestTrait;
use Eris\Generators;
composer require --dev giorgiosironi/eris.int, string, bool), collections (arrays, DateTime), and custom objects via suchThat or bind. Example:
$this->forAll(
Generators::tuple(
Generators::string()->minLength(5),
Generators::choose(1, 100)
)
)->then(fn([$name, $age]) => $this->assertTrue($age > 18 || strlen($name) > 10));
limitTo() and duration() to control test execution time.
sample() for quick validation or run Eris tests in parallel with PHPUnit’s --parallel flag.suchThat() to constrain generators tightly.@database or RefreshDatabase traits to avoid polluting test data.Generators::constant() for singletons).Model::factory()) or augment them?phpunit.xml configuration (e.g., grouping tests)?uses(TestTrait::class) in test files or extend a base test class.RefreshDatabase or @database traits to avoid side effects.Generators::json() or Generators::xml() for API payloads.Generators::array() or custom objects.@eris-repeat) may conflict with Laravel’s #[Test] or #[Assert] attributes. Prefer programmatic configuration.// Before (PHPUnit)
public function testOrderTotalIsPositive() {
$order = Order::factory()->create(['total' => 100]);
$this->assertGreaterThan(0, $order->total);
}
// After (Eris)
public function testOrderTotalIsAlwaysPositive() {
$this->forAll(Generators::choose(1, 1_000_000))
->then(fn($total) => $this->assertGreaterThan(0, $total));
}
meta field").composer.json:
"require-dev": {
"giorgiosironi/eris": "^1.0"
}
phpunit.xml to include Eris-specific configurations:
<php>
<env name="ERIS_SEED" value="12345"/> <!-- For reproducibility -->
</php>
~0.14.Generators::constant() for singletons).TestTrait over Laravel’s RefreshDatabase in the same class to avoid method conflicts.@eris-repeat) may clash with Laravel’s #[Test] or #[Assert]. Use programmatic configuration:
$this->forAll(Generators::string())
->repeat(100) // Instead of @eris-repeat
->then(...);
composer.json and run composer update.--stop-on-failure to catch regressions.limitTo()) to balance coverage and performance.sample() for quick validation in development.README.md or a PROPERTIES.md file).## Order Properties
- All order totals must be positive (Eris: `testOrderTotalIsAlwaysPositive`).
- All line items must have a valid product ID (Eris: `testLineItemProductIdExists`).
suchThat() to constrain generators to stable interfaces.How can I help you explore Laravel packages today?