giorgiosironi/eris
Eris brings QuickCheck-style property-based testing to PHP and PHPUnit. Define properties, generate many random inputs, and find minimal counterexamples automatically. Works with PHP 8.1–8.4 and PHPUnit 10–13.
hash(), bcrypt) or encryption logic with adversarial inputs.php artisan migrate with randomized schema changes).RefreshDatabase, MigrateFresh).~10MB) and dev-only (--dev), minimizing production impact.phpunit.xml (beyond adding the trait).| Risk Area | Severity | Mitigation |
|---|---|---|
| Test Flakiness | Medium | Use shrink() to isolate minimal failing inputs; pair with Laravel’s assertDatabaseHas/assertSoftDeleted. |
| Performance Overhead | Low | Eris is optimized for test-time use; disable in production via composer remove. |
| Generator Complexity | Medium | Start with simple generators (e.g., Generators::choose(), Generators::string()) before advanced combinators. |
| Debugging Shrinking | Medium | Leverage ERIS_ORIGINAL_INPUT=1 env var to inspect failing inputs. |
| PHPUnit Version Lock | Low | Laravel 10+ uses PHPUnit 10+, which Eris 1.0+ supports. |
| Legacy Code Impact | Low | Eris tests are additive; no breaking changes to existing test suites. |
Eris::forAll()) for consistency with Laravel’s syntax?Testing facade (e.g., actingAs(), withoutExceptionHandling)?Generators::date())?DatabaseTransactions)?TestTrait; no conflicts with Laravel’s TestCase.Generators::faker() (if extended) or custom generators for Eloquent model attributes.DatabaseMigrations trait to test schema changes.Http::post() or JsonResponse assertions.Generators::choose(1, 1000) requests.User::validatePassword() with:
public function testPasswordValidation()
{
$this->forAll(Generators::string(8, 32))
->then(function ($password) {
$user = User::factory()->create(['password' => bcrypt('correct_password'));
$this->assertFalse($user->validatePassword($password));
});
}
Generators::oneOf() to combine with existing test data.composer.json:
"require-dev": {
"giorgiosironi/eris": "^1.1"
}
phpunit.xml with Eris-specific listeners (optional):
<listeners>
<listener class="Eris\Listener\LogListener">
<arguments>
<argument value="storage/logs/eris.log"/>
</arguments>
</listener>
</listeners>
- name: Run Eris Tests
run: php artisan test --filter "ErisTest"
| Laravel Feature | Eris Compatibility | Workarounds |
|---|---|---|
| Database Transactions | ✅ Works with RefreshDatabase/MigrateFresh. |
Use Generators::date() for timestamped tests. |
API Testing (Http::fake()) |
✅ Generate randomized routes/payloads. | Combine with Laravel’s JsonResponse assertions. |
| Queues/Jobs | ✅ Test job payloads with Generators::array(). |
Use Generators::faker() for realistic data. |
Authentication (actingAs) |
✅ Works with Generators::uuid() for user IDs. |
Pair with Laravel’s actingAs() helper. |
| File Uploads | ⚠️ Limited (use Generators::string() + Storage::fake()). |
Mock uploads with Generators::binary(). |
| Notifications | ✅ Test notification channels with randomized data. | Use Generators::email() (custom generator). |
Localization (__()) |
❌ No direct support. | Pre-generate translated strings or use Generators::string(). |
DiscountCalculator with randomized input ranges.StoreProductRequest with malformed data.User::email uniqueness with Generators::email().Carbon instances for Auth::login() timeouts.How can I help you explore Laravel packages today?