PHPackages                             sti3bas/laravel-scout-array-driver - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. sti3bas/laravel-scout-array-driver

ActiveLibrary[Testing &amp; Quality](/categories/testing)

sti3bas/laravel-scout-array-driver
==================================

Array driver for Laravel Scout

v4.3(2mo ago)971.5M—4.5%12[4 issues](https://github.com/Sti3bas/laravel-scout-array-driver/issues)[1 PRs](https://github.com/Sti3bas/laravel-scout-array-driver/pulls)3MITPHPPHP ^8.0CI passing

Since Aug 25Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/Sti3bas/laravel-scout-array-driver)[ Packagist](https://packagist.org/packages/sti3bas/laravel-scout-array-driver)[ RSS](/packages/sti3bas-laravel-scout-array-driver/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (11)Versions (21)Used By (3)

Array driver for Laravel Scout
==============================

[](#array-driver-for-laravel-scout)

This package adds an `array` driver to Laravel Scout and provides custom PHPUnit assertions to make testing search related functionality easier.

Contents
--------

[](#contents)

- [Installation](#installation)
- [Usage](#usage)
- [License](#license)

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require sti3bas/laravel-scout-array-driver --dev
```

Set Scout driver to `array` in `.env.testing` file:

```
SCOUT_DRIVER=array

```

or in `phpunit.xml` file:

```

```

Usage
-----

[](#usage)

The [`Search`](src/Facades/Search.php) facade provides the following methods and assertions:

### assertContains($model, $callback = null)

[](#assertcontainsmodel-callback--null)

Checks if model exists in the search index.

```
$user = User::factory()->create([
    'name' => 'Oliver',
]);

$user2 = User::withoutSyncingToSearch(function () {
    return User::factory()->create([
        'name' => 'John',
    ]);
});

Search::assertContains($user) // ✅
    ->assertContains($user2) // ❌
    ->assertContains($user, function ($record) { // ✅
        return $record['name'] === 'Oliver';
    })
    ->assertContains($user, function ($record) { // ❌
        return $record['name'] === 'John';
    })
    ->assertContains($user2, function ($record) { // ❌
        return $record['name'] === 'John';
    });
```

### assertNotContains($model, $callback = null)

[](#assertnotcontainsmodel-callback--null)

Checks if model doesn't exist in the search index.

```
$user = User::factory()->create([
    'name' => 'Oliver',
]);

$user2 = User::withoutSyncingToSearch(function () {
    return User::factory()->create([
        'name' => 'John',
    ]);
});

Search::assertNotContains($user) // ❌
    ->assertNotContains($user2) // ✅
    ->assertNotContains($user, function ($record) { // ❌
        return $record['name'] === 'Oliver';
    })
    ->assertNotContains($user, function ($record) { // ✅
        return $record['name'] === 'John';
    })
    ->assertNotContains($user2, function ($record) { // ✅
        return $record['name'] === 'John';
    });
```

### assertContainsIn($index, $model, $callback = null)

[](#assertcontainsinindex-model-callback--null)

Checks if model exists in custom search index.

```
$user = User::factory()->create([
    'name' => 'Oliver',
]);

Search::assertContainsIn('users', $user) // ✅
    ->assertContainsIn('non_existing_index', $user) // ❌
    ->assertContainsIn('users', $user, function ($record) { // ✅
        return $record['name'] === 'Oliver';
    })
    ->assertContainsIn('users', $user, function ($record) { // ❌
        return $record['name'] === 'John';
    });
```

### assertNotContainsIn($index, $model, $callback = null)

[](#assertnotcontainsinindex-model-callback--null)

Checks if model doesn't exist in custom search index.

```
$user = User::factory()->create([
    'name' => 'Oliver',
]);

Search::assertNotContainsIn('users', $user) // ❌
    ->assertNotContainsIn('non_existing_index', $user) // ✅
    ->assertNotContainsIn('users', $user, function ($record) { // ❌
        return $record['name'] === 'Oliver';
    })
    ->assertNotContainsIn('users', $user, function ($record) { // ✅
        return $record['name'] === 'John';
    });
```

### assertEmpty()

[](#assertempty)

Checks if all search indexes are empty.

```
Search::assertEmpty(); // ✅

User::factory()->create();

Search::assertEmpty(); // ❌
```

### assertEmptyIn($index)

[](#assertemptyinindex)

Checks if search index is empty.

```
Search::assertEmptyIn('users'); // ✅

User::factory()->create();

Search::assertEmptyIn('users'); // ❌
```

### assertNotEmpty()

[](#assertnotempty)

Checks if there is at least one record in any of search indexes.

```
Search::assertNotEmpty(); // ❌

User::factory()->create();

Search::assertNotEmpty(); // ✅
```

### assertNotEmptyIn($index)

[](#assertnotemptyinindex)

Checks if search index is not empty.

```
Search::assertNotEmptyIn('users'); // ❌

User::factory()->create();

Search::assertNotEmptyIn('users'); // ✅
```

### assertCount($count)

[](#assertcountcount)

Checks if there is at least one record in any of search indexes.

```
Search::assertCount(1); // ❌

User::factory()->create();

Search::assertCount(1); // ✅
```

### assertCountIn($index)

[](#assertcountinindex)

Checks if search index is not empty.

```
Search::assertNotEmptyIn('users', 1); // ❌

User::factory()->create();

Search::assertNotEmptyIn('users', 1); // ✅
```

### assertSynced($model, $callback = null)

[](#assertsyncedmodel-callback--null)

Checks if model was synced to search index. This assertion checks every record of the given model which was synced during the request.

```
$user = User::factory()->create([
    'name' => 'Peter',
]);

Search::assertSynced($user); // ✅

$user->update(['name' => 'John']);
$user->delete();

Search::assertContains($user) // ❌
    ->assertSynced($user) // ✅
    ->assertSynced($user, function ($record) { // ✅
        return $record['name'] === 'Peter';
    })
    ->assertSynced($user, function ($record) { // ✅
        return $record['name'] === 'John';
    })
    ->assertSynced($user, function ($record) { // ❌
        return $record['name'] === 'Oliver';
    });
```

### assertNotSynced($model, $callback = null)

[](#assertnotsyncedmodel-callback--null)

Checks if model wasn't synced to search index. This assertion checks every record of the given model which was synced during the request.

```
$user = User::factory()->create([
    'name' => 'Peter',
]);

Search::assertNotSynced($user); // ❌

$user->update(['name' => 'John']);
$user->delete();

Search::assertContains($user) // ❌
    ->assertNotSynced($user); // ❌

Search::assertNotSynced($user, function ($record) { // ❌
    return $record['name'] === 'Peter';
})
->assertNotSynced($user, function ($record) { // ❌
    return $record['name'] === 'John';
})
->assertNotSynced($user, function ($record) { // ✅
    return $record['name'] === 'Oliver';
});
```

### assertSyncedTo($model, $callback = null)

[](#assertsyncedtomodel-callback--null)

Checks if model was synced to custom search index. This assertion checks every record of the given model which was synced during the request.

```
$user = User::factory()->create([
    'name' => 'Peter',
]);

Search::assertSyncedTo('users', $user); // ✅

$user->update(['name' => 'John']);
$user->delete();

Search::assertContains($user) // ❌
    ->assertSyncedTo('users', $user) // ✅
    ->assertSyncedTo('users', $user, function ($record) {
        return $record['name'] === 'Peter'; // ✅
    })
    ->assertSyncedTo('users', $user, function ($record) {
        return $record['name'] === 'John'; // ✅
    })
    ->assertSyncedTo('non_existing_index', $user, function ($record) {
        return $record['name'] === 'John'; // ❌
    });
```

### assertNotSyncedTo($model, $callback = null)

[](#assertnotsyncedtomodel-callback--null)

Checks if model wasn't synced to custom search index. This assertion checks every record of the given model which was synced during the request.

```
$user = User::factory()->create([
    'name' => 'Peter',
]);

Search::assertNotSyncedTo('users', $user) // ❌
    ->assertNotSyncedTo('not_existing_index', $user); // ✅

$user->update(['name' => 'John']);
$user->delete();

Search::assertContains($user) // ❌
    ->assertNotSyncedTo('users', $user) // ❌
    ->assertNotSyncedTo('users', $user, function ($record) {
        return $record['name'] === 'Peter'; // ❌
    })
    ->assertNotSyncedTo('users', $user, function ($record) {
        return $record['name'] === 'Oliver'; // ✅
    });
```

### assertSyncedTimes($model, $callback = null)

[](#assertsyncedtimesmodel-callback--null)

Checks if model was synced expected number of times. This assertion checks every record of the given model which was synced during the request.

```
$user = User::withoutSyncingToSearch(function () {
    return User::factory()->create([
        'name' => 'Peter',
    ]);
});

Search::assertSyncedTimes($user, 0) // ✅
    ->assertSyncedTimes($user, 1); // ❌

$user->searchable();
$user->update(['name' => 'John']);
$user->delete();

Search::assertContains($user) // ❌
    ->assertSyncedTimes($user, 2) // ✅
    ->assertSyncedTimes($user, 1, function ($record) {
        return $record['name'] === 'Peter'; // ✅
    })
    ->assertSyncedTimes($user, 1, function ($record) {
        return $record['name'] === 'John'; // ✅
    })
    ->assertSyncedTimes($user, 1, function ($record) {
        return $record['name'] === 'Oliver'; // ❌
    });
```

### assertSyncedTimesTo($index, $model, $callback = null)

[](#assertsyncedtimestoindex-model-callback--null)

Checks if model was synced to custom search index expected number of times. This assertion checks every record of the given model which was synced during the request.

```
$user = User::withoutSyncingToSearch(function () {
    return User::factory()->create([
        'name' => 'Peter',
    ]);
});

Search::assertSyncedTimesTo('users', $user, 0) // ✅
    ->assertSyncedTimesTo('non_existing_index', $user, 1); // ❌

$user->searchable();
$user->update(['name' => 'John']);
$user->delete();

Search::assertContains($user) // ❌
    ->assertSyncedTimesTo('users', $user, 2) // ✅
    ->assertSyncedTimesTo('users', $user, 1, function ($record) {
        return $record['name'] === 'Peter'; // ✅
    })
    ->assertSyncedTimesTo('non_existing_index', 1, function ($record) {
        return $record['name'] === 'John'; // ❌
    });
```

### assertNothingSynced()

[](#assertnothingsynced)

Checks if nothing was synced to any of search indexes. This assertion checks every record which was synced during the request.

```
Search::assertNothingSynced(); // ✅

User::factory()->create();

Search::assertNothingSynced(); // ❌
```

### assertNothingSyncedTo()

[](#assertnothingsyncedto)

Checks if nothing was synced to custom search index. This assertion checks every record which was synced during the request.

```
Search::assertNothingSyncedTo('users'); // ✅

User::factory()->create();

Search::assertNothingSyncedTo('users'); // ❌
```

### assertIndexExists($index)

[](#assertindexexistsindex)

Checks if search index exists.

```
$manager = $this->app->make(EngineManager::class);

$engine = $manager->engine();

Search::assertIndexExists('test'); // ❌

$engine->createIndex('test');

Search::assertIndexExists('test'); // ✅
```

### assertIndexNotExists($index)

[](#assertindexnotexistsindex)

Checks if search index doesn't exist.

```
$manager = $this->app->make(EngineManager::class);

$engine = $manager->engine();

Search::assertIndexNotExists('test'); // ✅

$engine->createIndex('test');

Search::assertIndexNotExists('test'); // ❌
```

### fakeRecord($model, $data, $merge = true, $index = null)

[](#fakerecordmodel-data-merge--true-index--null)

This method allows to fake search index record of the model. It will not affect assertions.

```
$user = User::factory()->create([
    'id' => 123,
    'name' => 'Peter',
    'email' => 'peter@example.com',
]);

Search::fakeRecord($user, [
    'name' => 'John',
]);

$record = User::search()->where('id', 123)->raw()['hits'][0];

$this->assertEquals('Peter', $record['name']); // ❌
$this->assertEquals('John', $record['name']); // ✅
$this->assertEquals('peter@example.com', $record['email']); // ✅

Search::fakeRecord($user, [
    'id' => 123,
    'name' => 'John',
], false);

$record = User::search()->where('id', 123)->raw()['hits'][0];

$this->assertEquals('Peter', $record['name']); // ❌
$this->assertEquals('John', $record['name']); // ✅
$this->assertTrue(!isset($record['email'])); // ✅
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance86

Actively maintained with recent releases

Popularity55

Moderate usage in the ecosystem

Community25

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 59.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~139 days

Recently: every ~183 days

Total

18

Last Release

85d ago

Major Versions

v1.0.2 → v2.02020-03-03

v2.2.1 → v3.02021-05-01

v3.5 → v4.02024-02-21

PHP version history (6 changes)v1.0PHP ^7.1.3

v2.0PHP ^7.2

v2.2PHP ^7.2|^8.0

v3.0PHP ^7.3|^8.0

v3.4PHP ^8.0

v4.0PHP ^8.0 || ^8.1 || ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/8168c9b2fba4eb7fcd960a3652765c8789bbbe148ce9fbcbebd549c031ebeac8?d=identicon)[Sti3bas](/maintainers/Sti3bas)

---

Top Contributors

[![Sti3bas](https://avatars.githubusercontent.com/u/17280721?v=4)](https://github.com/Sti3bas "Sti3bas (22 commits)")[![tabuna](https://avatars.githubusercontent.com/u/5102591?v=4)](https://github.com/tabuna "tabuna (3 commits)")[![sebastiaanluca](https://avatars.githubusercontent.com/u/711940?v=4)](https://github.com/sebastiaanluca "sebastiaanluca (2 commits)")[![sweptsquash](https://avatars.githubusercontent.com/u/9886472?v=4)](https://github.com/sweptsquash "sweptsquash (2 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (1 commits)")[![lpointetf](https://avatars.githubusercontent.com/u/22477737?v=4)](https://github.com/lpointetf "lpointetf (1 commits)")[![arondeparon](https://avatars.githubusercontent.com/u/7697?v=4)](https://github.com/arondeparon "arondeparon (1 commits)")[![owenvoke](https://avatars.githubusercontent.com/u/1899334?v=4)](https://github.com/owenvoke "owenvoke (1 commits)")[![marianogoldman](https://avatars.githubusercontent.com/u/959563?v=4)](https://github.com/marianogoldman "marianogoldman (1 commits)")[![cbaconnier](https://avatars.githubusercontent.com/u/4738184?v=4)](https://github.com/cbaconnier "cbaconnier (1 commits)")[![devsquad-pedro-silva](https://avatars.githubusercontent.com/u/93937477?v=4)](https://github.com/devsquad-pedro-silva "devsquad-pedro-silva (1 commits)")[![JoseVte](https://avatars.githubusercontent.com/u/3540836?v=4)](https://github.com/JoseVte "JoseVte (1 commits)")

---

Tags

testinglaravelarraydriverscout

###  Code Quality

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/sti3bas-laravel-scout-array-driver/health.svg)

```
[![Health](https://phpackages.com/badges/sti3bas-laravel-scout-array-driver/health.svg)](https://phpackages.com/packages/sti3bas-laravel-scout-array-driver)
```

###  Alternatives

[laravel/scout

Laravel Scout provides a driver based solution to searching your Eloquent models.

1.7k49.4M479](/packages/laravel-scout)[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k25.9M107](/packages/laravel-cashier)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[yadahan/laravel-authentication-log

Laravel Authentication Log provides authentication logger and notification for Laravel.

416632.8k5](/packages/yadahan-laravel-authentication-log)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
