The package is designed for two complementary test layers:
- Unit tests compile Scout builders without opening a Redis connection.
- Integration tests run the Laravel application against Redis Stack and verify real
FT.SEARCHbehaviour.
Package unit tests
The package test suite uses a fake RedisSearchConnection, so contributors can
run it without Docker:
composer install
composer test
composer test:unit
composer lint
The fake connection records commands and hashes. This makes it easy to assert
the exact compiled query, for example Ad*, filter ranges, or SORTBY options.
Application integration tests
Install the package in the Laravel application and start Redis Stack. Add the provided trait to the feature test class:
use BurakSevinc\ScoutRedisSearch\Testing\InteractsWithRedisSearch;
final class UserSearchTest extends TestCase
{
use InteractsWithRedisSearch;
protected function setUp(): void
{
parent::setUp();
$this->recreateRedisSearchIndex('users');
}
public function test_it_finds_a_user_by_name_prefix(): void
{
User::factory()->create(['name' => 'Ada Lovelace'])->searchable();
$results = User::search('Ad')->get();
$this->assertCount(1, $results);
$this->assertSame('Ada Lovelace', $results->first()->name);
$this->assertRedisSearchIndexExists('users');
}
}
Available helpers are:
| Helper | Purpose |
|---|---|
recreateRedisSearchIndex($index) |
Drop an existing index and create it from config |
dropRedisSearchIndex($index) |
Remove an index when a test needs a clean teardown |
assertRedisSearchIndexExists($index) |
Assert that an index is present |
assertRedisSearchIndexMissing($index) |
Assert that an index is absent |
redisSearchEngine() |
Resolve the registered package engine |
Use a dedicated Redis database or container for tests. Recreating an index with
DD deletes the documents belonging to that index.
What to cover
An application integration suite should exercise the flows that matter to users:
User::search('Ad')->get();
User::search('Ada')->options(['fuzzy' => 1])->get();
User::search('')->where('id', '>=', 10)->paginate(15);
$user->searchable();
$user->unsearchable();
The example application at scout-test covers these flows against a live Redis
Stack container.
Copy-ready Laravel example
The package repository includes a consumer-side example at
examples/laravel/tests/Feature/UserSearchTest.php. Copy it into a Laravel
application’s tests/Feature directory and run it with:
php artisan test --filter=UserSearchTest
The example keeps application integration tests separate from the package’s
Redis-free unit suite while documenting the same real Redis Stack workflow used
by scout-test.