josiasmontag / laravel-redis-mock
This Laravel package provides a Redis mock for your tests
Installs: 1 222 496
Dependents: 15
Suggesters: 0
Security: 0
Stars: 44
Watchers: 3
Forks: 10
Open Issues: 1
Requires
- php: >=7.1.0
- laravel/framework: ^5.8.30|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- m6web/redis-mock: ^4.2|^5.0
- predis/predis: ^1.1|^2.0
Requires (Dev)
- orchestra/testbench: ~3.8.0|^4.0|^5.0|^6.0|^7.0|^8.0|^9.0
- phpunit/phpunit: ^7.0|^8.0|^9.5.10|^10.5
README
This Laravel package provides a Redis mock for your tests. It depends on Redis PHP Mock.
This makes it possible to run your tests without any local Redis server running!
Installation & Usage
To get started, use Composer to add the package to your project's dependencies:
composer require josiasmontag/laravel-redis-mock
This package adds a new mock
Redis client.
In config/database.php
, make the Redis client configurable via environment variable:
'redis' => [ 'client' => env('REDIS_CLIENT', 'predis'), ... ],
Now, you can switch to the mock
client in your .env.testing
:
REDIS_CLIENT=mock
Alternatively, you can switch to the mock in your phpunit.xml
:
<env name="REDIS_CLIENT" value="mock"/>
Done! Your tests should work without a local redis server running.
Package Development
If you are using Redis as part of a Laravel package, you should already have a TestCase.php
that is extending Orchestra\Testbench\Testcase
.
Within this file you should add RedisMockServiceProvider
to getPackageProviders
method
e.g.
/**
* @param $app
* @return string[]
*/
protected function getPackageProviders($app): array
{
return [
YourPackageServiceProvider::class,
\Lunaweb\RedisMock\Providers\RedisMockServiceProvider::class
];
}