Skip to content

Merge v1.21 into v2.1 #1749

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

Merged
merged 3 commits into from
Aug 13, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ public function __construct(?string $uri = null, array $uriOptions = [], array $
$this->uri = $uri ?? self::DEFAULT_URI;
$this->builderEncoder = $driverOptions['builderEncoder'] ?? new BuilderEncoder();
$this->typeMap = $driverOptions['typeMap'];

/* Database and Collection objects may need to know whether auto
* encryption is enabled for dropping collections. Track this via an
* internal option until PHPC-2615 is implemented. */
$this->autoEncryptionEnabled = isset($driverOptions['autoEncryption']['keyVaultNamespace']);

$driverOptions = array_diff_key($driverOptions, ['builderEncoder' => 1, 'typeMap' => 1]);
Expand Down
1 change: 1 addition & 0 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,7 @@ public function watch(array|Pipeline $pipeline = [], array $options = []): Chang
public function withOptions(array $options = []): Collection
{
$options += [
'autoEncryptionEnabled' => $this->autoEncryptionEnabled,
'builderEncoder' => $this->builderEncoder,
'codec' => $this->codec,
'readConcern' => $this->readConcern,
Expand Down
1 change: 1 addition & 0 deletions src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ public function watch(array|Pipeline $pipeline = [], array $options = []): Chang
public function withOptions(array $options = []): Database
{
$options += [
'autoEncryptionEnabled' => $this->autoEncryptionEnabled,
'builderEncoder' => $this->builderEncoder,
'readConcern' => $this->readConcern,
'readPreference' => $this->readPreference,
Expand Down
21 changes: 21 additions & 0 deletions tests/Collection/CollectionFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use MongoDB\Operation\Count;
use MongoDB\Tests\CommandObserver;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;

Check failure on line 20 in tests/Collection/CollectionFunctionalTest.php

View workflow job for this annotation

GitHub Actions / phpcs

Type PHPUnit\Framework\Attributes\Group is not used in this file.
use ReflectionClass;
use TypeError;

use function array_filter;
Expand Down Expand Up @@ -405,6 +407,16 @@
foreach ($collectionOptions as $key => $value) {
$this->assertSame($value, $debug[$key]);
}

// autoEncryptionEnabled is an internal option not reported via debug info
$collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName(), ['autoEncryptionEnabled' => true]);
$clone = $collection->withOptions();

$rc = new ReflectionClass($clone);
$rp = $rc->getProperty('autoEncryptionEnabled');
$rp->setAccessible(true);

$this->assertSame(true, $rp->getValue($clone));
}

public function testWithOptionsPassesOptions(): void
Expand All @@ -424,6 +436,15 @@
foreach ($collectionOptions as $key => $value) {
$this->assertSame($value, $debug[$key]);
}

// autoEncryptionEnabled is an internal option not reported via debug info
$clone = $this->collection->withOptions(['autoEncryptionEnabled' => true]);

$rc = new ReflectionClass($clone);
$rp = $rc->getProperty('autoEncryptionEnabled');
$rp->setAccessible(true);

$this->assertSame(true, $rp->getValue($clone));
}

public static function collectionMethodClosures()
Expand Down
20 changes: 20 additions & 0 deletions tests/Database/DatabaseFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use MongoDB\Operation\CreateIndexes;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use ReflectionClass;
use TypeError;

use function array_key_exists;
Expand Down Expand Up @@ -385,6 +386,16 @@ public function testWithOptionsInheritsOptions(): void
foreach ($databaseOptions as $key => $value) {
$this->assertSame($value, $debug[$key]);
}

// autoEncryptionEnabled is an internal option not reported via debug info
$database = new Database($this->manager, $this->getDatabaseName(), ['autoEncryptionEnabled' => true]);
$clone = $database->withOptions();

$rc = new ReflectionClass($clone);
$rp = $rc->getProperty('autoEncryptionEnabled');
$rp->setAccessible(true);

$this->assertSame(true, $rp->getValue($clone));
}

public function testWithOptionsPassesOptions(): void
Expand All @@ -403,5 +414,14 @@ public function testWithOptionsPassesOptions(): void
foreach ($databaseOptions as $key => $value) {
$this->assertSame($value, $debug[$key]);
}

// autoEncryptionEnabled is an internal option not reported via debug info
$clone = $this->database->withOptions(['autoEncryptionEnabled' => true]);

$rc = new ReflectionClass($clone);
$rp = $rc->getProperty('autoEncryptionEnabled');
$rp->setAccessible(true);

$this->assertSame(true, $rp->getValue($clone));
}
}
Loading