Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge v1.x into v2.x #1483

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,8 @@ public function listIndexes(array $options = [])
*/
public function listSearchIndexes(array $options = []): Iterator
{
$options = $this->inheritTypeMap($options);

$operation = new ListSearchIndexes($this->databaseName, $this->collectionName, $options);
$server = select_server($this->manager, $options);

Expand Down
28 changes: 28 additions & 0 deletions tests/Collection/CollectionFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use MongoDB\Collection;
use MongoDB\Database;
use MongoDB\Driver\BulkWrite;
use MongoDB\Driver\Exception\CommandException;
use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\WriteConcern;
Expand All @@ -23,6 +24,7 @@
use function array_filter;
use function call_user_func;
use function is_scalar;
use function iterator_to_array;
use function json_encode;
use function str_contains;
use function usort;
Expand Down Expand Up @@ -800,6 +802,32 @@ public function testMethodInTransactionWithReadConcernOption($method): void
}
}

public function testListSearchIndexesInheritTypeMap(): void
{
$this->skipIfAtlasSearchIndexIsNotSupported();

$collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName(), ['typeMap' => ['root' => 'array']]);

// Insert a document to create the collection
$collection->insertOne(['_id' => 1]);

try {
$collection->createSearchIndex(['mappings' => ['dynamic' => false]], ['name' => 'test-search-index']);
} catch (CommandException $e) {
// Ignore duplicate errors in case this test is re-run too quickly
// Index is asynchronously dropped during tearDown, we only need to
// ensure it exists for this test.
if ($e->getCode() !== 68 /* IndexAlreadyExists */) {
throw $e;
}
}

$indexes = $collection->listSearchIndexes();
$indexes = iterator_to_array($indexes);
$this->assertCount(1, $indexes);
$this->assertIsArray($indexes[0]);
}

/**
* Create data fixtures.
*/
Expand Down
9 changes: 9 additions & 0 deletions tests/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,15 @@ protected function skipIfServerVersion(string $operator, string $version, ?strin
}
}

protected function skipIfAtlasSearchIndexIsNotSupported(): void
{
if (! self::isAtlas()) {
self::markTestSkipped('Search Indexes are only supported on MongoDB Atlas 7.0+');
}

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

protected function skipIfChangeStreamIsNotSupported(): void
{
if ($this->isStandalone()) {
Expand Down
6 changes: 1 addition & 5 deletions tests/SpecTests/SearchIndexSpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,9 @@ class SearchIndexSpecTest extends FunctionalTestCase

public function setUp(): void
{
if (! self::isAtlas()) {
self::markTestSkipped('Search Indexes are only supported on MongoDB Atlas 7.0+');
}

parent::setUp();

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

/**
Expand Down