|
8 | 8 | use MongoDB\Collection; |
9 | 9 | use MongoDB\Database; |
10 | 10 | use MongoDB\Driver\BulkWrite; |
| 11 | +use MongoDB\Driver\Exception\CommandException; |
11 | 12 | use MongoDB\Driver\ReadConcern; |
12 | 13 | use MongoDB\Driver\ReadPreference; |
13 | 14 | use MongoDB\Driver\WriteConcern; |
|
23 | 24 | use function array_filter; |
24 | 25 | use function call_user_func; |
25 | 26 | use function is_scalar; |
| 27 | +use function iterator_to_array; |
26 | 28 | use function json_encode; |
27 | 29 | use function str_contains; |
28 | 30 | use function usort; |
@@ -800,6 +802,32 @@ public function testMethodInTransactionWithReadConcernOption($method): void |
800 | 802 | } |
801 | 803 | } |
802 | 804 |
|
| 805 | + public function testListSearchIndexesInheritTypeMap(): void |
| 806 | + { |
| 807 | + $this->skipIfAtlasSearchIndexIsNotSupported(); |
| 808 | + |
| 809 | + $collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName(), ['typeMap' => ['root' => 'array']]); |
| 810 | + |
| 811 | + // Insert a document to create the collection |
| 812 | + $collection->insertOne(['_id' => 1]); |
| 813 | + |
| 814 | + try { |
| 815 | + $collection->createSearchIndex(['mappings' => ['dynamic' => false]], ['name' => 'test-search-index']); |
| 816 | + } catch (CommandException $e) { |
| 817 | + // Ignore duplicate errors in case this test is re-run too quickly |
| 818 | + // Index is asynchronously dropped during tearDown, we only need to |
| 819 | + // ensure it exists for this test. |
| 820 | + if ($e->getCode() !== 68 /* IndexAlreadyExists */) { |
| 821 | + throw $e; |
| 822 | + } |
| 823 | + } |
| 824 | + |
| 825 | + $indexes = $collection->listSearchIndexes(); |
| 826 | + $indexes = iterator_to_array($indexes); |
| 827 | + $this->assertCount(1, $indexes); |
| 828 | + $this->assertIsArray($indexes[0]); |
| 829 | + } |
| 830 | + |
803 | 831 | /** |
804 | 832 | * Create data fixtures. |
805 | 833 | */ |
|
0 commit comments