Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Eris Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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.

Implementation Patterns

  • Combinator-based Generators: Chain Generator\ combinators (oneOf, tuple, arrayOf, unique) to model complex input scenarios (e.g., validating sorting algorithms with random permutations).
  • Shrinking for Debugging: Let Eris shrink failing inputs automatically—no manual minimization needed. Leverage this to get minimal counterexamples.
  • Integration with PHPUnit: Use @dataProvider for manual fixtures and forAll for broad coverage; combine them in the same class.
  • Performance Tuning: Use ->withMaxSize(10) or ->withMinSize(5) to bound generator complexity, and set --eris-repetitions=1000 in phpunit.xml for thorough runs without slowing CI.
  • Custom Generators: Extend Eris\Generator\GeneratorInterface for domain-specific types (e.g., validEmail(), nonEmptyString()).

Gotchas and Tips

  • Shrinking Limitations: Complex nested structures (e.g., deeply nested arrays) may shrink poorly—test edge cases first with small inputs.
  • No assertThrows in Property: Eris assertions don’t support exception expectations directly. Wrap risky code in try/catch, then assert on captured exceptions inside then().
  • Static Analysis Interference: Psalm/PHPStan may flag Generator\* calls as undefined—use @phpstan-ignore-next-line or import aliases (use Eris\Generator;).
  • Generator State: Generators are stateless, but then() closures must be side-effect free—avoid mocking or DB writes. For external dependencies, isolate logic inside the property and test pure transforms.
  • CI Failures: If Eris\TestCase isn’t discovered, ensure your phpunit.xml includes --bootstrap and the autoloader loads vendor/autoload.php.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport