PDO connections with Mockery-based mocks, allowing fine-grained control over SQL queries and responses.mockery-pdo: Requires an alpha version of mpyw/mockery-pdo, introducing external dependency risk (unproven stability).mockery-pdo is in alpha, risking instability or missing features.Carbon::setTestNow() for timestamp mocking—may conflict with existing test setups.DB::raw(), subqueries, joins)?mockery-pdo reach stable 1.0? What’s the upgrade path?DatabaseMigrations, Factory testing, or PestPHP’s mocking?fake()).DatabaseTransactions or RefreshDatabase with mocks for fast feedback.mockery-pdo to a specific alpha version to avoid surprises.mockery-pdo.Carbon::setTestNow()—ensure no conflicts with existing time-mocking tools.composer require mpyw/laravel-database-mock mpyw/mockery-pdo:dev-alpha
phpunit.xml:
<php>
<env name="MOCKERY" value="1"/>
</php>
DatabaseMigrations with DBMock in test setup:
public function setUp(): void
{
parent::setUp();
DBMock::mockPdo(); // Global mock or per-test
}
$pdo = DBMock::mockPdo();
$pdo->shouldSelect('SELECT * FROM users')->shouldFetchAllReturns([...]);
mockery-pdo) requires close monitoring for stability.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Unmocked query executed | Test fails unpredictably | Use DBMock::verifyAllMocks() |
mockery-pdo breaks |
Tests fail silently | Pin to a specific alpha version |
| Query expectations mismatch | Flaky tests | Log all mocked queries in CI |
| Carbon timestamp conflicts | Incorrect created_at values |
Isolate timestamp mocking per test |
| Complex SQL (e.g., raw queries) | Unsupported syntax | Fall back to real DB for edge cases |
| Package abandonment | No future updates | Fork or seek alternatives (e.g., Pest) |
DBMock syntax.WHERE IN clause."How can I help you explore Laravel packages today?