josiasmontag/laravel-redis-mock
Drop-in Redis mock for Laravel tests using Redis PHP Mock. Adds a “mock” Redis client so you can run test suites without a running Redis server. Enable via REDIS_CLIENT=mock in .env.testing/phpunit.xml; works with Testbench for package dev.
Redis::connection()), requiring minimal changes to existing Redis usage. No architectural conflicts with Laravel 13’s updated service provider bootstrapping.ServiceProvider class structure. No manual configuration needed beyond package installation.composer.json.beforeEach/afterEach hooks may simplify mock lifecycle management, but explicit cleanup (e.g., Redis::flush()) is still recommended for shared state.EVAL, SORT). No changes to this risk; manual validation of critical paths (e.g., pub/sub, transactions) remains necessary.redis config and Illuminate/Redis facade. No conflicts with other packages (e.g., spatie/laravel-redis). Updated: Compatible with Laravel 13’s new service container and dependency injection improvements.Redis::connection()->get('key') with mock assertions.Redis::fake() (if supported) for scoped mocks.redis:work).ext-redis is installed in composer.json dev dependencies (PHP 8.2+).predis/predis), the package may not work—manual mocking would still be required. (Unchanged)composer require --dev josiasmontag/laravel-redis-mock
php artisan vendor:publish --provider="JosiasMontag\RedisMock\RedisMockServiceProvider"
Updated: Ensure config is compatible with Laravel 13’s updated service provider structure.Redis::connection() with mock assertions.use JosiasMontag\RedisMock\Facades\Redis;
test('cache mock works', function () {
Redis::shouldReceive('get')->with('key')->andReturn('mocked');
expect(Redis::get('key'))->toBe('mocked');
});
redis:work queue commands).Redis::fake() to test setup (if supported).EVAL support), tests may need adjustments. New: Check for Laravel 13-specific Redis features (e.g., redis:work) in future releases.Redis::flush() in afterEach).Redis::fake() per test class).
Updated: Pest 2.0’s parallel execution may increase flakiness risk; document cleanup strategies.mockery. (Unchanged)--parallel), but shared state must be managed. Updated: Pest 2.0’s parallelism may expose race conditions in mocks; test thoroughly.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Mock misses a Redis command | Tests pass but fail in production | Manually stub unsupported commands |
| Shared state causes test pollution | Flaky tests | Use Redis::fake() per test or flush |
| Package abandonment | Broken tests | Fork or switch to mockery |
| CI/CD misconfiguration | Tests run against real Redis | Validate .env.testing uses mocks |
| Laravel 13-specific Redis features unsupported | Tests fail for new Redis logic (e.g., redis:work) |
Manually mock or use |
How can I help you explore Laravel packages today?