Skip to content

Commit f399d24

Browse files
Merge v1.21 into v2.1 (#1749)
2 parents 002fad6 + 205685c commit f399d24

File tree

5 files changed

+46
-0
lines changed

5 files changed

+46
-0
lines changed

src/Client.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ public function __construct(?string $uri = null, array $uriOptions = [], array $
135135
$this->uri = $uri ?? self::DEFAULT_URI;
136136
$this->builderEncoder = $driverOptions['builderEncoder'] ?? new BuilderEncoder();
137137
$this->typeMap = $driverOptions['typeMap'];
138+
139+
/* Database and Collection objects may need to know whether auto
140+
* encryption is enabled for dropping collections. Track this via an
141+
* internal option until PHPC-2615 is implemented. */
138142
$this->autoEncryptionEnabled = isset($driverOptions['autoEncryption']['keyVaultNamespace']);
139143

140144
$driverOptions = array_diff_key($driverOptions, ['builderEncoder' => 1, 'typeMap' => 1]);

src/Collection.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,7 @@ public function watch(array|Pipeline $pipeline = [], array $options = []): Chang
10631063
public function withOptions(array $options = []): Collection
10641064
{
10651065
$options += [
1066+
'autoEncryptionEnabled' => $this->autoEncryptionEnabled,
10661067
'builderEncoder' => $this->builderEncoder,
10671068
'codec' => $this->codec,
10681069
'readConcern' => $this->readConcern,

src/Database.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ public function watch(array|Pipeline $pipeline = [], array $options = []): Chang
632632
public function withOptions(array $options = []): Database
633633
{
634634
$options += [
635+
'autoEncryptionEnabled' => $this->autoEncryptionEnabled,
635636
'builderEncoder' => $this->builderEncoder,
636637
'readConcern' => $this->readConcern,
637638
'readPreference' => $this->readPreference,

tests/Collection/CollectionFunctionalTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use MongoDB\Operation\Count;
1818
use MongoDB\Tests\CommandObserver;
1919
use PHPUnit\Framework\Attributes\DataProvider;
20+
use ReflectionClass;
2021
use TypeError;
2122

2223
use function array_filter;
@@ -405,6 +406,16 @@ public function testWithOptionsInheritsOptions(): void
405406
foreach ($collectionOptions as $key => $value) {
406407
$this->assertSame($value, $debug[$key]);
407408
}
409+
410+
// autoEncryptionEnabled is an internal option not reported via debug info
411+
$collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName(), ['autoEncryptionEnabled' => true]);
412+
$clone = $collection->withOptions();
413+
414+
$rc = new ReflectionClass($clone);
415+
$rp = $rc->getProperty('autoEncryptionEnabled');
416+
$rp->setAccessible(true);
417+
418+
$this->assertSame(true, $rp->getValue($clone));
408419
}
409420

410421
public function testWithOptionsPassesOptions(): void
@@ -424,6 +435,15 @@ public function testWithOptionsPassesOptions(): void
424435
foreach ($collectionOptions as $key => $value) {
425436
$this->assertSame($value, $debug[$key]);
426437
}
438+
439+
// autoEncryptionEnabled is an internal option not reported via debug info
440+
$clone = $this->collection->withOptions(['autoEncryptionEnabled' => true]);
441+
442+
$rc = new ReflectionClass($clone);
443+
$rp = $rc->getProperty('autoEncryptionEnabled');
444+
$rp->setAccessible(true);
445+
446+
$this->assertSame(true, $rp->getValue($clone));
427447
}
428448

429449
public static function collectionMethodClosures()

tests/Database/DatabaseFunctionalTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use MongoDB\Operation\CreateIndexes;
1616
use PHPUnit\Framework\Attributes\DataProvider;
1717
use PHPUnit\Framework\Attributes\Group;
18+
use ReflectionClass;
1819
use TypeError;
1920

2021
use function array_key_exists;
@@ -385,6 +386,16 @@ public function testWithOptionsInheritsOptions(): void
385386
foreach ($databaseOptions as $key => $value) {
386387
$this->assertSame($value, $debug[$key]);
387388
}
389+
390+
// autoEncryptionEnabled is an internal option not reported via debug info
391+
$database = new Database($this->manager, $this->getDatabaseName(), ['autoEncryptionEnabled' => true]);
392+
$clone = $database->withOptions();
393+
394+
$rc = new ReflectionClass($clone);
395+
$rp = $rc->getProperty('autoEncryptionEnabled');
396+
$rp->setAccessible(true);
397+
398+
$this->assertSame(true, $rp->getValue($clone));
388399
}
389400

390401
public function testWithOptionsPassesOptions(): void
@@ -403,5 +414,14 @@ public function testWithOptionsPassesOptions(): void
403414
foreach ($databaseOptions as $key => $value) {
404415
$this->assertSame($value, $debug[$key]);
405416
}
417+
418+
// autoEncryptionEnabled is an internal option not reported via debug info
419+
$clone = $this->database->withOptions(['autoEncryptionEnabled' => true]);
420+
421+
$rc = new ReflectionClass($clone);
422+
$rp = $rc->getProperty('autoEncryptionEnabled');
423+
$rp->setAccessible(true);
424+
425+
$this->assertSame(true, $rp->getValue($clone));
406426
}
407427
}

0 commit comments

Comments
 (0)