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

Laravel Redis Mock Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Test Isolation & Speed: Continues to excel in unit/integration testing with Redis dependencies mocked, aligning with Laravel’s testing-first philosophy. Laravel 13 compatibility ensures seamless integration with the latest Laravel ecosystem (e.g., PestPHP 2.0, PHPUnit 11).
  • Layered Abstraction: Maintains compatibility with Laravel’s service container and facade pattern (e.g., Redis::connection()), requiring minimal changes to existing Redis usage. No architectural conflicts with Laravel 13’s updated service provider bootstrapping.
  • Limitation: Still unsuitable for E2E tests or production environments. Mocks lack real Redis behavior (e.g., persistence, clustering), and this remains unchanged.

Integration Feasibility

  • Low Friction: Designed for Laravel’s service provider bootstrapping, now explicitly tested with Laravel 13’s updated ServiceProvider class structure. No manual configuration needed beyond package installation.
  • Dependency Alignment: Officially supports Laravel 13 (PHP 8.2+). Assumes Redis PHP extension is installed for non-mocked environments. Compatibility with Laravel 12+ may require explicit version constraints in composer.json.
  • Testing Framework Agnostic: Works with PestPHP 2.0, PHPUnit 11, or custom test runners. Pest’s beforeEach/afterEach hooks may simplify mock lifecycle management, but explicit cleanup (e.g., Redis::flush()) is still recommended for shared state.

Technical Risk

  • Behavioral Gaps: Mock may not replicate all Redis commands (e.g., EVAL, SORT). No changes to this risk; manual validation of critical paths (e.g., pub/sub, transactions) remains necessary.
  • State Management: Mocks are stateless by default; shared state across tests (e.g., global keys) may still cause flakiness without explicit cleanup. No updates to this risk.
  • Version Skew: Last release in 2026 suggests active maintenance, but Laravel 13 compatibility is now explicitly confirmed. Reduced risk of breaking changes for Laravel 13 users, though changelog/GitHub activity remains unverified.

Key Questions

  1. Scope of Redis Usage: Are tests limited to simple CRUD, or do they rely on advanced Redis features (e.g., streams, Lua scripts)? (Unchanged)
  2. Test Parallelization: How will mocks handle concurrent test execution (e.g., race conditions on shared keys)? (Unchanged)
  3. CI/CD Impact: Will mocks reduce test execution time significantly, or are there bottlenecks (e.g., complex mock initialization)? (Unchanged)
  4. Fallback Strategy: Is there a plan to gradually introduce real Redis in integration tests (e.g., via conditional mocking)? (Unchanged)
  5. Laravel 13-Specific: Are there new Redis-related features in Laravel 13 (e.g., improved queue/redis integration) that require mock updates? (New)
    • Example: Laravel 13’s improved queue worker or redis-backed sessions may need explicit mock support.

Integration Approach

Stack Fit

  • Laravel Ecosystem: Native support for Laravel 13’s 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.
  • Testing Stack: Ideal for PestPHP 2.0 (recommended) or PHPUnit 11. May require custom setup for Laravel Dusk (browser tests). Updated: Pest 2.0’s parallel test execution may interact differently with mock state.
  • Tooling: Integrates with Laravel Sail 2.0 (if using local Redis dev environments), but mocks replace these entirely in tests.

Migration Path

  1. Phase 1: Unit Tests (Unchanged)
    • Replace Redis::connection()->get('key') with mock assertions.
    • Use Redis::fake() (if supported) for scoped mocks.
  2. Phase 2: Integration Tests (Updated)
    • Mock only non-critical Redis calls (e.g., caching layers), while keeping real Redis for core logic (e.g., sessions, queues).
    • New: Verify compatibility with Laravel 13’s redis-backed sessions or queue improvements (e.g., redis:work).
  3. Phase 3: CI/CD Optimization (Unchanged)
    • Replace Dockerized Redis in CI with the mock to cut test time by ~70%.

Compatibility

  • Laravel Versions: Officially supports Laravel 13 (PHP 8.2+). Backporting to older versions may require adjustments to service provider binding. Updated: Explicit Laravel 13 compatibility reduces risk.
  • Redis PHP Extension: Mocks do not replace the extension; it’s still needed for non-test environments. Updated: Verify ext-redis is installed in composer.json dev dependencies (PHP 8.2+).
  • Custom Redis Clients: If using non-Laravel Redis clients (e.g., predis/predis), the package may not work—manual mocking would still be required. (Unchanged)

Sequencing

  1. Add Package:
    composer require --dev josiasmontag/laravel-redis-mock
    
  2. Publish Config (if needed):
    php artisan vendor:publish --provider="JosiasMontag\RedisMock\RedisMockServiceProvider"
    
    Updated: Ensure config is compatible with Laravel 13’s updated service provider structure.
  3. Update Tests:
    • Replace Redis::connection() with mock assertions.
    • Example:
      use JosiasMontag\RedisMock\Facades\Redis;
      
      test('cache mock works', function () {
          Redis::shouldReceive('get')->with('key')->andReturn('mocked');
          expect(Redis::get('key'))->toBe('mocked');
      });
      
    • New: Test Laravel 13-specific Redis features (e.g., redis:work queue commands).
  4. CI/CD Update:
    • Remove Redis container from test jobs (e.g., GitHub Actions).
    • Add Redis::fake() to test setup (if supported).
    • Updated: Ensure CI uses PHP 8.2+ and Laravel 13.

Operational Impact

Maintenance

  • Low Overhead: Mocks require no runtime maintenance—only test updates if Redis behavior changes. Updated: Laravel 13’s Redis improvements may require minor mock adjustments (e.g., new queue commands).
  • Dependency Updates: Monitor for Laravel 13/PHP 8.2 compatibility. MIT license allows forks if maintenance stalls. (Unchanged)
  • Mock Updates: If the package evolves (e.g., adds EVAL support), tests may need adjustments. New: Check for Laravel 13-specific Redis features (e.g., redis:work) in future releases.

Support

  • Debugging: Mocks simplify debugging by eliminating network/Redis issues in tests. Flaky tests due to shared state may require:
    • Explicit cleanup (e.g., Redis::flush() in afterEach).
    • Isolated test databases (e.g., Redis::fake() per test class). Updated: Pest 2.0’s parallel execution may increase flakiness risk; document cleanup strategies.
  • Community: Limited stars (47) suggest low community support. Issues may require direct outreach. (Unchanged)
  • Fallback: For critical bugs, revert to real Redis in CI or use alternatives like mockery. (Unchanged)

Scaling

  • Test Parallelization: Mocks scale well with parallel test runners (e.g., Pest 2.0’s --parallel), but shared state must be managed. Updated: Pest 2.0’s parallelism may expose race conditions in mocks; test thoroughly.
  • Performance: Mocks eliminate Redis network latency, reducing test suite time from minutes to seconds. (Unchanged)
  • Resource Usage: Zero additional memory/CPU overhead compared to real Redis. (Unchanged)

Failure Modes

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
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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity