Skip to content

Commit caf4013

Browse files
committed
Fix detection for mongodb community 5
1 parent 6c73f9d commit caf4013

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/Exception/SearchNotSupportedException.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,31 @@ public static function create(ServerException $e): self
2020
}
2121

2222
/** @internal */
23-
public static function isSearchNotSupportedError(Throwable $e): bool
23+
public static function isSearchNotSupportedError(Throwable $exception): bool
2424
{
25-
if (! $e instanceof ServerException) {
25+
if (! $exception instanceof ServerException) {
2626
return false;
2727
}
2828

29-
return match ($e->getCode()) {
29+
return match ($exception->getCode()) {
3030
// MongoDB 8: Using Atlas Search Database Commands and the $listSearchIndexes aggregation stage requires additional configuration.
3131
31082 => true,
3232
// MongoDB 7: $listSearchIndexes stage is only allowed on MongoDB Atlas
3333
6047401 => true,
3434
// MongoDB 7-ent: Search index commands are only supported with Atlas.
3535
115 => true,
3636
// MongoDB 4 to 6, 7-community
37-
59 => 'no such command: \'createSearchIndexes\'' === $e->getMessage(),
37+
59 => match ($exception->getMessage()) {
38+
'no such command: \'createSearchIndexes\'' => true,
39+
'no such command: \'updateSearchIndex\'' => true,
40+
'no such command: \'dropSearchIndex\'' => true,
41+
default => false,
42+
},
3843
// MongoDB 4 to 6
39-
40324 => 'Unrecognized pipeline stage name: \'$listSearchIndexes\'' === $e->getMessage(),
44+
40324 => match ($exception->getMessage()) {
45+
'Unrecognized pipeline stage name: \'$listSearchIndexes\'' => true,
46+
default => false,
47+
},
4048
// Not an Atlas Search error
4149
default => false,
4250
};

tests/Exception/SearchNotSupportedExceptionTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class SearchNotSupportedExceptionTest extends FunctionalTestCase
1313
#[DoesNotPerformAssertions]
1414
public function testListSearchIndexesNotSupportedException(): void
1515
{
16-
$collection = $this->createCollection($this->getDatabaseName(), 'SearchNotSupportedException');
16+
$collection = $this->createCollection($this->getDatabaseName(), $this->getCollectionName());
1717

1818
try {
1919
$collection->listSearchIndexes();
@@ -24,9 +24,9 @@ public function testListSearchIndexesNotSupportedException(): void
2424
}
2525

2626
#[DoesNotPerformAssertions]
27-
public function testCreateSearchIndexNotSupportedException(): void
27+
public function testSearchIndexManagementNotSupportedException(): void
2828
{
29-
$collection = $this->createCollection($this->getDatabaseName(), 'SearchNotSupportedException');
29+
$collection = $this->createCollection($this->getDatabaseName(), $this->getCollectionName());
3030

3131
try {
3232
$collection->createSearchIndex(['mappings' => ['dynamic' => false]], ['name' => 'test-search-index']);
@@ -52,7 +52,7 @@ public function testCreateSearchIndexNotSupportedException(): void
5252

5353
public function testOtherStageNotFound(): void
5454
{
55-
$collection = $this->createCollection($this->getDatabaseName(), 'SearchNotSupportedException');
55+
$collection = $this->createCollection($this->getDatabaseName(), $this->getCollectionName());
5656

5757
try {
5858
$collection->aggregate([

0 commit comments

Comments
 (0)