Skip to content

Commit 7e7494d

Browse files
Merge v1.x into v2.x (#1483)
2 parents 01e307e + 85e8502 commit 7e7494d

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

src/Collection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,8 @@ public function listIndexes(array $options = []): Iterator
890890
*/
891891
public function listSearchIndexes(array $options = []): Iterator
892892
{
893+
$options = $this->inheritTypeMap($options);
894+
893895
$operation = new ListSearchIndexes($this->databaseName, $this->collectionName, $options);
894896
$server = select_server($this->manager, $options);
895897

tests/Collection/CollectionFunctionalTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use MongoDB\Collection;
88
use MongoDB\Database;
99
use MongoDB\Driver\BulkWrite;
10+
use MongoDB\Driver\Exception\CommandException;
1011
use MongoDB\Driver\ReadConcern;
1112
use MongoDB\Driver\ReadPreference;
1213
use MongoDB\Driver\WriteConcern;
@@ -20,6 +21,7 @@
2021
use function array_filter;
2122
use function call_user_func;
2223
use function is_scalar;
24+
use function iterator_to_array;
2325
use function json_encode;
2426
use function str_contains;
2527
use function usort;
@@ -751,6 +753,32 @@ public function testMethodInTransactionWithReadConcernOption($method): void
751753
}
752754
}
753755

756+
public function testListSearchIndexesInheritTypeMap(): void
757+
{
758+
$this->skipIfAtlasSearchIndexIsNotSupported();
759+
760+
$collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName(), ['typeMap' => ['root' => 'array']]);
761+
762+
// Insert a document to create the collection
763+
$collection->insertOne(['_id' => 1]);
764+
765+
try {
766+
$collection->createSearchIndex(['mappings' => ['dynamic' => false]], ['name' => 'test-search-index']);
767+
} catch (CommandException $e) {
768+
// Ignore duplicate errors in case this test is re-run too quickly
769+
// Index is asynchronously dropped during tearDown, we only need to
770+
// ensure it exists for this test.
771+
if ($e->getCode() !== 68 /* IndexAlreadyExists */) {
772+
throw $e;
773+
}
774+
}
775+
776+
$indexes = $collection->listSearchIndexes();
777+
$indexes = iterator_to_array($indexes);
778+
$this->assertCount(1, $indexes);
779+
$this->assertIsArray($indexes[0]);
780+
}
781+
754782
/**
755783
* Create data fixtures.
756784
*/

tests/FunctionalTestCase.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,15 @@ protected function skipIfServerVersion(string $operator, string $version, ?strin
454454
}
455455
}
456456

457+
protected function skipIfAtlasSearchIndexIsNotSupported(): void
458+
{
459+
if (! self::isAtlas()) {
460+
self::markTestSkipped('Search Indexes are only supported on MongoDB Atlas 7.0+');
461+
}
462+
463+
$this->skipIfServerVersion('<', '7.0', 'Search Indexes are only supported on MongoDB Atlas 7.0+');
464+
}
465+
457466
protected function skipIfChangeStreamIsNotSupported(): void
458467
{
459468
if ($this->isStandalone()) {

tests/SpecTests/SearchIndexSpecTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,9 @@ class SearchIndexSpecTest extends FunctionalTestCase
2929

3030
public function setUp(): void
3131
{
32-
if (! self::isAtlas()) {
33-
self::markTestSkipped('Search Indexes are only supported on MongoDB Atlas 7.0+');
34-
}
35-
3632
parent::setUp();
3733

38-
$this->skipIfServerVersion('<', '7.0', 'Search Indexes are only supported on MongoDB Atlas 7.0+');
34+
$this->skipIfAtlasSearchIndexIsNotSupported();
3935
}
4036

4137
/**

0 commit comments

Comments
 (0)