giorgiosironi/eris
Property-based testing library for PHP. Generate random inputs, shrink failing cases, and find edge bugs automatically. Eris integrates with PHPUnit to make tests more robust and expressive, inspired by QuickCheck-style generators and combinators.
Eris brings property-based testing (PBT) to PHP via PHPUnit, inspired by Haskell’s QuickCheck. Begin by installing it via Composer: composer require --dev giorgiosironi/eris. Next, extend Eris\TestCase (or use traits like Eris\Trait\PropertyTesting) in your test class. Start with a simple property—e.g., verifying commutativity of addition—using the forAll generator API:
$this->forAll(Generator\int(), Generator\int())
->then(function ($a, $b) {
$this->assertEquals($a + $b, $b + $a);
});
Check the tests/ directory in the repo for minimal examples (e.g., tests/Property/CommutativityTest.php). The README’s "Quickstart" section is the best first reference.
Generator\ combinators (oneOf, tuple, arrayOf, unique) to model complex input scenarios (e.g., validating sorting algorithms with random permutations).@dataProvider for manual fixtures and forAll for broad coverage; combine them in the same class.->withMaxSize(10) or ->withMinSize(5) to bound generator complexity, and set --eris-repetitions=1000 in phpunit.xml for thorough runs without slowing CI.Eris\Generator\GeneratorInterface for domain-specific types (e.g., validEmail(), nonEmptyString()).assertThrows in Property: Eris assertions don’t support exception expectations directly. Wrap risky code in try/catch, then assert on captured exceptions inside then().Generator\* calls as undefined—use @phpstan-ignore-next-line or import aliases (use Eris\Generator;).then() closures must be side-effect free—avoid mocking or DB writes. For external dependencies, isolate logic inside the property and test pure transforms.Eris\TestCase isn’t discovered, ensure your phpunit.xml includes --bootstrap and the autoloader loads vendor/autoload.php.How can I help you explore Laravel packages today?