1313use Doctrine \Bundle \MongoDBBundle \Tests \DependencyInjection \Fixtures \Bundles \DocumentListenerBundle \EventListener \TestAttributeListener ;
1414use Doctrine \ODM \MongoDB \Configuration ;
1515use Doctrine \ODM \MongoDB \Mapping \Annotations ;
16+ use InvalidArgumentException ;
1617use MongoDB \Client ;
1718use PHPUnit \Framework \Attributes \DataProvider ;
1819use 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