Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b38f88f

Browse files
committed
Rebased on AtlasSearchTest
1 parent e7c202d commit b38f88f

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

‎src/Schema/Builder.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@ public function getIndexes($table)
253253
try {
254254
$indexes = $collection->listSearchIndexes(['typeMap' => ['root' => 'array', 'array' => 'array', 'document' => 'array']]);
255255
foreach ($indexes as $index) {
256+
// Status 'DOES_NOT_EXIST' means the index has been dropped but is still in the process of being removed
257+
if ($index['status'] === 'DOES_NOT_EXIST') {
258+
continue;
259+
}
260+
256261
$indexList[] = [
257262
'name' => $index['name'],
258263
'columns' => match ($index['type']) {

‎tests/SchemaTest.php‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
use Illuminate\Support\Facades\DB;
88
use Illuminate\Support\Facades\Schema;
99
use MongoDB\BSON\Binary;
10-
use MongoDB\BSON\Document;
1110
use MongoDB\BSON\UTCDateTime;
1211
use MongoDB\Collection;
12+
use MongoDB\Database;
1313
use MongoDB\Laravel\Schema\Blueprint;
1414

1515
use function assert;
@@ -20,8 +20,10 @@ class SchemaTest extends TestCase
2020
{
2121
public function tearDown(): void
2222
{
23-
Schema::drop('newcollection');
24-
Schema::drop('newcollection_two');
23+
$database = $this->getConnection('mongodb')->getMongoDB();
24+
assert($database instanceof Database);
25+
$database->dropCollection('newcollection');
26+
$database->dropCollection('newcollection_two');
2527
}
2628

2729
public function testCreate(): void
@@ -477,6 +479,7 @@ public function testGetColumns()
477479
$this->assertSame([], $columns);
478480
}
479481

482+
/** @see AtlasSearchTest::testGetIndexes() */
480483
public function testGetIndexes()
481484
{
482485
Schema::create('newcollection', function (Blueprint $collection) {
@@ -584,12 +587,12 @@ protected function getIndex(string $collection, string $name)
584587
return false;
585588
}
586589

587-
protected function getSearchIndex(string $collection, string $name): ?Document
590+
protected function getSearchIndex(string $collection, string $name): ?array
588591
{
589592
$collection = DB::getCollection($collection);
590593
assert($collection instanceof Collection);
591594

592-
foreach ($collection->listSearchIndexes(['name' => $name, 'typeMap' => ['root' => 'bson']]) as $index) {
595+
foreach ($collection->listSearchIndexes(['name' => $name, 'typeMap' => ['root' => 'array', 'array' => 'array', 'document' => 'array']]) as $index) {
593596
return $index;
594597
}
595598

‎tests/TestCase.php‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Foundation\Application;
88
use MongoDB\Driver\Exception\ServerException;
99
use MongoDB\Laravel\MongoDBServiceProvider;
10+
use MongoDB\Laravel\Schema\Builder;
1011
use MongoDB\Laravel\Tests\Models\User;
1112
use MongoDB\Laravel\Validation\ValidationServiceProvider;
1213
use Orchestra\Testbench\TestCase as OrchestraTestCase;
@@ -71,16 +72,8 @@ public function skipIfSearchIndexManagementIsNotSupported(): void
7172
try {
7273
$this->getConnection('mongodb')->getCollection('test')->listSearchIndexes(['name' => 'just_for_testing']);
7374
} catch (ServerException $e) {
74-
switch ($e->getCode()) {
75-
// MongoDB 6: Unrecognized pipeline stage name: '$listSearchIndexes'
76-
case 40324:
77-
// MongoDB 7: PlanExecutor error during aggregation :: caused by :: Search index commands are only supported with Atlas.
78-
case 115:
79-
// MongoDB 7: $listSearchIndexes stage is only allowed on MongoDB Atlas
80-
case 6047401:
81-
// MongoDB 8: Using Atlas Search Database Commands and the $listSearchIndexes aggregation stage requires additional configuration.
82-
case 31082:
83-
self::markTestSkipped('Search index management is not supported on this server');
75+
if (Builder::isAtlasSearchNotSupportedException($e)) {
76+
self::markTestSkipped('Search index management is not supported on this server');
8477
}
8578

8679
throw $e;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /