Skip to content

Commit aa385dd

Browse files
committed
Add testing docs
1 parent 91af444 commit aa385dd

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ ActiveRedis provides you simple and efficient way to interact with Redis hashes
3434
- [Querying Models](#querying-models)
3535
- [Chunking](#chunking)
3636
- [Searching](#searching)
37+
- [Testing](#testing)
3738
- [Credits](#credits)
3839

3940
## Requirements
@@ -680,6 +681,35 @@ $visit = Visit::create(['user_id' => 1]);
680681
$visit->update(['user_id' => 2]);
681682
```
682683

684+
## Testing
685+
686+
To run your application tests without a real Redis server, you may swap the underlying repository to an array.
687+
688+
This will allow you to test with your models without needing to interact with Redis:
689+
690+
```php
691+
use DirectoryTree\ActiveRedis\Model;
692+
693+
Model::setRepository('array');
694+
```
695+
696+
Otherwise, you will need to run your tests with a Redis server running, and flush your Redis database after each test:
697+
698+
```php
699+
use Illuminate\Support\Facades\Redis;
700+
701+
// Pest
702+
beforeEach(fn () => Redis::flushdb());
703+
704+
// PHPUnit
705+
protected function setUp(): void
706+
{
707+
parent::setUp();
708+
709+
Redis::flushdb();
710+
}
711+
```
712+
683713
## Credits
684714

685715
This package is directly inspired from <a href="https://laravel.com/docs/eloquent">Laravel's Eloquent</a>, and most features are direct ports to a Redis equivalent.

0 commit comments

Comments
 (0)