Skip to content

Commit

Permalink
Add testing docs
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebauman committed Nov 19, 2024
1 parent 91af444 commit aa385dd
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ ActiveRedis provides you simple and efficient way to interact with Redis hashes
- [Querying Models](#querying-models)
- [Chunking](#chunking)
- [Searching](#searching)
- [Testing](#testing)
- [Credits](#credits)

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

## Testing

To run your application tests without a real Redis server, you may swap the underlying repository to an array.

This will allow you to test with your models without needing to interact with Redis:

```php
use DirectoryTree\ActiveRedis\Model;

Model::setRepository('array');
```

Otherwise, you will need to run your tests with a Redis server running, and flush your Redis database after each test:

```php
use Illuminate\Support\Facades\Redis;

// Pest
beforeEach(fn () => Redis::flushdb());

// PHPUnit
protected function setUp(): void
{
parent::setUp();

Redis::flushdb();
}
```

## Credits

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.
Expand Down

0 comments on commit aa385dd

Please sign in to comment.