Skip to content

Commit f13fde6

Browse files
committed
Fix compatibility with mongodb-odm < 1.12
1 parent 7183f33 commit f13fde6

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

phpstan-baseline.neon

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,24 @@ parameters:
534534
count: 1
535535
path: tests/DependencyInjection/ConfigurationTest.php
536536

537+
-
538+
message: '#^Call to an undefined method Doctrine\\ODM\\MongoDB\\Configuration\:\:getDefaultKmsProvider\(\)\.$#'
539+
identifier: method.notFound
540+
count: 3
541+
path: tests/DependencyInjection/DoctrineMongoDBExtensionTest.php
542+
543+
-
544+
message: '#^Call to an undefined method Doctrine\\ODM\\MongoDB\\Configuration\:\:getDefaultMasterKey\(\)\.$#'
545+
identifier: method.notFound
546+
count: 3
547+
path: tests/DependencyInjection/DoctrineMongoDBExtensionTest.php
548+
549+
-
550+
message: '#^Call to an undefined method Doctrine\\ODM\\MongoDB\\Configuration\:\:getDriverOptions\(\)\.$#'
551+
identifier: method.notFound
552+
count: 7
553+
path: tests/DependencyInjection/DoctrineMongoDBExtensionTest.php
554+
537555
-
538556
message: '#^Method Doctrine\\Bundle\\MongoDBBundle\\Tests\\DependencyInjection\\DoctrineMongoDBExtensionTest\:\:assertDICDefinitionMethodCall\(\) has parameter \$params with no value type specified in iterable type array\.$#'
539557
identifier: missingType.iterableValue

src/DependencyInjection/DoctrineMongoDBExtension.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,10 @@ protected function loadDocumentManager(array $documentManager, string|null $defa
293293
];
294294

295295
if (isset($connections[$connectionName]['autoEncryption'])) {
296+
if (! method_exists(ODMConfiguration::class, 'setAutoEncryption')) {
297+
throw new InvalidArgumentException(sprintf('The "autoEncryption" option requires doctrine/mongodb-odm version 2.12 or higher, "%s" installed.', self::getODMVersion()));
298+
}
299+
296300
$autoEncryption = $connections[$connectionName]['autoEncryption'];
297301
$methods['setAutoEncryption'] = array_diff_key(
298302
$this->normalizeAutoEncryption($autoEncryption, $defaultDB),

tests/DependencyInjection/DoctrineMongoDBExtensionTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Doctrine\Bundle\MongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\DocumentListenerBundle\EventListener\TestAttributeListener;
1414
use Doctrine\ODM\MongoDB\Configuration;
1515
use Doctrine\ODM\MongoDB\Mapping\Annotations;
16+
use InvalidArgumentException;
1617
use MongoDB\Client;
1718
use PHPUnit\Framework\Attributes\DataProvider;
1819
use PHPUnit\Framework\TestCase;
@@ -488,6 +489,8 @@ public function testUseTransactionalFlush(): void
488489

489490
public function testAutoEncryptionWithKeyVaultClientService(): void
490491
{
492+
self::requireAutoEncryptionSupportInODM();
493+
491494
$container = $this->buildMinimalContainer();
492495
$loader = new DoctrineMongoDBExtension();
493496

@@ -538,6 +541,8 @@ public function testAutoEncryptionWithKeyVaultClientService(): void
538541

539542
public function testAutoEncryptionWithComplexKmsAndSchemaMap(): void
540543
{
544+
self::requireAutoEncryptionSupportInODM();
545+
541546
$container = $this->buildMinimalContainer();
542547
$loader = new DoctrineMongoDBExtension();
543548

@@ -590,6 +595,8 @@ public function testAutoEncryptionWithComplexKmsAndSchemaMap(): void
590595

591596
public function testAutoEncryptionWithExtraOptions(): void
592597
{
598+
self::requireAutoEncryptionSupportInODM();
599+
593600
$container = $this->buildMinimalContainer();
594601
$loader = new DoctrineMongoDBExtension();
595602

@@ -639,6 +646,8 @@ public function testAutoEncryptionWithExtraOptions(): void
639646

640647
public function testAutoEncryptionWithEmptyKmsProvider(): void
641648
{
649+
self::requireAutoEncryptionSupportInODM();
650+
642651
$container = $this->buildMinimalContainer();
643652
$loader = new DoctrineMongoDBExtension();
644653

@@ -663,4 +672,36 @@ public function testAutoEncryptionWithEmptyKmsProvider(): void
663672
self::assertArrayHasKey('autoEncryption', $driverOptions);
664673
self::assertEquals(['aws' => new Definition(stdClass::class)], $driverOptions['autoEncryption']['kmsProviders']);
665674
}
675+
676+
public function testAutoEncryptionMinimumODMVersion(): void
677+
{
678+
if (InstalledVersions::satisfies(new VersionParser(), 'doctrine/mongodb-odm', '>=2.12@dev')) {
679+
self::markTestSkipped('Installed version of doctrine/mongodb-odm does support auto encryption');
680+
}
681+
682+
$container = $this->buildMinimalContainer();
683+
$loader = new DoctrineMongoDBExtension();
684+
685+
$config = [
686+
'connections' => [
687+
'default' => [
688+
'autoEncryption' => [
689+
'kmsProvider' => ['type' => 'aws'],
690+
],
691+
],
692+
],
693+
'document_managers' => ['default' => []],
694+
];
695+
696+
self::expectException(InvalidArgumentException::class);
697+
self::expectExceptionMessage('The "autoEncryption" option requires doctrine/mongodb-odm version 2.12 or higher');
698+
$loader->load([$config], $container);
699+
}
700+
701+
private static function requireAutoEncryptionSupportInODM(): void
702+
{
703+
if (! InstalledVersions::satisfies(new VersionParser(), 'doctrine/mongodb-odm', '>=2.12@dev')) {
704+
self::markTestSkipped('Installed version of doctrine/mongodb-odm does not support auto encryption');
705+
}
706+
}
666707
}

0 commit comments

Comments
 (0)