Skip to content

Commit f593e6a

Browse files
committed
Skip tests that require Atlas Search
1 parent 4374ee4 commit f593e6a

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

src/Schema/Blueprint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
* quantization?: 'none'|'scalar'|'binary',
8888
* } | array{
8989
* type: 'filter',
90-
* path: string,
90+
* path: string,
9191
* }
9292
* @phpstan-type TypeVectorSearchIndexDefinition array{
9393
* fields: array<string, TypeVectorSearchIndexField>,

tests/SchemaTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,10 @@ public function testGetIndexes()
504504
$this->assertSame([], $indexes);
505505
}
506506

507-
/** @todo requires SearchIndex support */
508507
public function testSearchIndex(): void
509508
{
509+
$this->skipIfSearchIndexManagementIsNotSupported();
510+
510511
Schema::create('newcollection', function (Blueprint $collection) {
511512
$collection->searchIndex([
512513
'mappings' => [
@@ -529,6 +530,8 @@ public function testSearchIndex(): void
529530

530531
public function testVectorSearchIndex()
531532
{
533+
$this->skipIfSearchIndexManagementIsNotSupported();
534+
532535
Schema::create('newcollection', function (Blueprint $collection) {
533536
$collection->vectorSearchIndex([
534537
'fields' => [

tests/TestCase.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace MongoDB\Laravel\Tests;
66

77
use Illuminate\Foundation\Application;
8+
use MongoDB\Driver\Exception\ServerException;
89
use MongoDB\Laravel\MongoDBServiceProvider;
910
use MongoDB\Laravel\Tests\Models\User;
1011
use MongoDB\Laravel\Validation\ValidationServiceProvider;
@@ -64,4 +65,23 @@ protected function getEnvironmentSetUp($app): void
6465
$app['config']->set('queue.failed.database', 'mongodb2');
6566
$app['config']->set('queue.failed.driver', 'mongodb');
6667
}
68+
69+
public function skipIfSearchIndexManagementIsNotSupported(): void
70+
{
71+
try {
72+
$this->getConnection('mongodb')->getCollection('test')->listSearchIndexes(['name' => 'just_for_testing']);
73+
} 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 8: Using Atlas Search Database Commands and the $listSearchIndexes aggregation stage requires additional configuration.
80+
case 31082:
81+
self::markTestSkipped('Search index management is not supported on this server');
82+
}
83+
84+
throw $e;
85+
}
86+
}
6787
}

0 commit comments

Comments
 (0)