Strengths:
Weaknesses:
whereHas, with) as thoroughly as dedicated testing libraries like Mockery + DatabaseMigrations.Key Use Cases:
imanghafoori/eloquent-mockery).Mockery or PHPUnit extensions if overlapping functionality exists.Laravel\Pest\Factories) if not configured to coexist.| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Test flakiness | Medium | Pair with RefreshDatabase or DatabaseTransactions for edge cases. |
| Query complexity | Low | Supplement with Mockery for unsupported Eloquent methods. |
| Version compatibility | Low | Monitor Laravel/Eloquent breaking changes (e.g., query builder APIs). |
| Team adoption | Medium | Provide migration guides and examples. |
hydrate, macro queries) critical to the test suite?// Before: Database-dependent test
public function test_user_creation()
{
$user = User::create([...]);
$this->assertDatabaseHas('users', [...]);
}
// After: Mocked test
use Imanghafoori\EloquentMockery\EloquentMockery;
public function test_user_creation()
{
EloquentMockery::mock(User::class, [
'create' => fn($data) => new User($data)
]);
$user = User::create([...]);
$this->assertInstanceOf(User::class, $user);
}
DatabaseTransactions in favor of mocks for unit tests (keep for integration tests).| Component | Compatibility Status | Notes |
|---|---|---|
| Laravel 9+ | ✅ Full | Tested against latest Laravel versions. |
| PHP 8.1+ | ✅ Full | Requires named arguments. |
| Eloquent | ✅ Full | Covers basic CRUD and query builder. |
| Mockery | ⚠️ Partial | May overlap; prefer one or the other. |
| Pest/PHPUnit | ✅ Full | Works as a test helper. |
| Factories | ⚠️ Conditional | Avoid mixing with EloquentMockery. |
create, find, update).belongsTo, hasMany).firstOrFail, pluck).save() instead of testing validation).EloquentMockery::mock()).beforeEach in Pest/PHPUnit).RefreshDatabase (disable for mocked tests).DatabaseMigrations or Testcontainers).| Failure Mode | Impact | Mitigation |
|---|---|---|
| Over-mocking | Tests pass but hide bugs. | Enforce a test pyramid (more unit, fewer integration tests). |
| Mock-Logic Drift | Mocks break when business logic changes. | Use feature flags or contract tests. |
| False Assumptions | Mocks assume implementation details. | Prefer behavior-based assertions (e.g., "user was created" vs. "ID=1"). |
| Toolchain Conflicts | Clashes with factories/DB tools. | Isolate mocks to specific test files. |
EloquentMockery within 3 months.How can I help you explore Laravel packages today?