Skip to content

Commit 54bf40d

Browse files
committed
Skip tests that require Atlas Search
1 parent 631141e commit 54bf40d

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
@@ -525,9 +525,10 @@ public function testGetIndexes()
525525
$this->assertSame([], $indexes);
526526
}
527527

528-
/** @todo requires SearchIndex support */
529528
public function testSearchIndex(): void
530529
{
530+
$this->skipIfSearchIndexManagementIsNotSupported();
531+
531532
Schema::create('newcollection', function (Blueprint $collection) {
532533
$collection->searchIndex([
533534
'mappings' => [
@@ -550,6 +551,8 @@ public function testSearchIndex(): void
550551

551552
public function testVectorSearchIndex()
552553
{
554+
$this->skipIfSearchIndexManagementIsNotSupported();
555+
553556
Schema::create('newcollection', function (Blueprint $collection) {
554557
$collection->vectorSearchIndex([
555558
'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)