Skip to content

Commit 7aeffd7

Browse files
authored
ScoutEngine: fix delete() TypeError message to reference EloquentCollection (#3457)
1 parent e23e5a7 commit 7aeffd7

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Scout/ScoutEngine.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function update($models)
151151
#[Override]
152152
public function delete($models): void
153153
{
154-
assert($models instanceof EloquentCollection, new TypeError(sprintf('Argument #1 ($models) must be of type %s, %s given', Collection::class, get_debug_type($models))));
154+
assert($models instanceof EloquentCollection, new TypeError(sprintf('Argument #1 ($models) must be of type %s, %s given', EloquentCollection::class, get_debug_type($models))));
155155

156156
if ($models->isEmpty()) {
157157
return;

tests/Scout/ScoutEngineTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use MongoDB\Laravel\Tests\Scout\Models\SearchableModel;
2222
use MongoDB\Laravel\Tests\TestCase;
2323
use PHPUnit\Framework\Attributes\DataProvider;
24+
use TypeError;
2425

2526
use function array_replace_recursive;
2627
use function count;
@@ -670,4 +671,17 @@ public function testDeleteWithRemoveableScoutCollection(): void
670671
$engine = new ScoutEngine($database, softDelete: false);
671672
$engine->delete($job->models);
672673
}
674+
675+
public function testDeleteRejectsNonEloquentCollection(): void
676+
{
677+
$database = $this->createMock(Database::class);
678+
$engine = new ScoutEngine($database, softDelete: false);
679+
680+
$this->expectException(TypeError::class);
681+
$this->expectExceptionMessage(
682+
'Argument #1 ($models) must be of type Illuminate\Database\Eloquent\Collection',
683+
);
684+
685+
$engine->delete(LaravelCollection::make([1, 2, 3]));
686+
}
673687
}

0 commit comments

Comments
 (0)