Skip to content

Commit

Permalink
Merge v1.x into v2.x (#1483)
Browse files Browse the repository at this point in the history
  • Loading branch information
mongodb-php-bot authored Oct 15, 2024
2 parents 01e307e + 85e8502 commit 7e7494d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,8 @@ public function listIndexes(array $options = []): Iterator
*/
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 @@ -7,6 +7,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 @@ -20,6 +21,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 @@ -751,6 +753,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 @@ -454,6 +454,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

0 comments on commit 7e7494d

Please sign in to comment.