From c4391110e646ca48f35aea72bc23d014001747ef Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Wed, 1 Sep 2021 02:45:09 +0200 Subject: [PATCH] Add compiler pass tests --- .../Compiler/CacheCompatibilityPassTest.php | 69 +++++++++++++++++ .../Fixtures/TestKernel.php | 76 +++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 Tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php create mode 100644 Tests/DependencyInjection/Fixtures/TestKernel.php diff --git a/Tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php b/Tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php new file mode 100644 index 00000000..09fb92f6 --- /dev/null +++ b/Tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php @@ -0,0 +1,69 @@ +load(static function (ContainerBuilder $containerBuilder): void { + $containerBuilder->loadFromExtension( + 'doctrine_mongodb', + ['document_managers' => ['default' => ['metadata_cache_driver' => ['type' => 'service', 'id' => 'custom_cache_service']]]] + ); + $containerBuilder->setDefinition( + 'custom_cache_service', + new Definition(ArrayAdapter::class) + ); + }); + } + })->boot(); + } + + /** + * @group legacy + */ + public function testMetadataCacheConfigUsingNonPsr6ServiceDefinedByApplication(): void + { + $this->expectDeprecation('Since doctrine/mongodb-odm-bundle 4.4: Configuring doctrine/cache is deprecated. Please update the cache service "custom_cache_service" to use a PSR-6 cache.'); + (new class (false) extends TestKernel { + public function registerContainerConfiguration(LoaderInterface $loader): void + { + parent::registerContainerConfiguration($loader); + $loader->load(static function (ContainerBuilder $containerBuilder): void { + $containerBuilder->loadFromExtension( + 'doctrine_mongodb', + ['document_managers' => ['default' => ['metadata_cache_driver' => ['type' => 'service', 'id' => 'custom_cache_service']]]] + ); + $containerBuilder->setDefinition( + 'custom_cache_service', + (new Definition(DoctrineProvider::class)) + ->setArguments([new Definition(ArrayAdapter::class)]) + ->setFactory([DoctrineProvider::class, 'wrap']) + ); + }); + } + })->boot(); + } +} diff --git a/Tests/DependencyInjection/Fixtures/TestKernel.php b/Tests/DependencyInjection/Fixtures/TestKernel.php new file mode 100644 index 00000000..236991ac --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/TestKernel.php @@ -0,0 +1,76 @@ + */ + public function registerBundles(): iterable + { + return [ + new FrameworkBundle(), + new DoctrineMongoDBBundle(), + ]; + } + + public function registerContainerConfiguration(LoaderInterface $loader): void + { + $loader->load(static function (ContainerBuilder $container): void { + $container->loadFromExtension('framework', ['secret' => 'F00']); + + $container->loadFromExtension('doctrine_mongodb', [ + 'connections' => ['default' => []], + 'document_managers' => [ + 'default' => [ + 'mappings' => [ + 'RepositoryServiceBundle' => [ + 'type' => 'annotation', + 'dir' => __DIR__ . '/Bundles/RepositoryServiceBundle/Document', + 'prefix' => 'Fixtures\Bundles\RepositoryServiceBundle\Document', + ], + ], + ], + ], + ]); + + // Register a NullLogger to avoid getting the stderr default logger of FrameworkBundle + $container->register('logger', NullLogger::class); + }); + } + + public function getProjectDir(): string + { + if ($this->projectDir === null) { + $this->projectDir = sys_get_temp_dir() . '/sf_kernel_' . md5((string) mt_rand()); + } + + return $this->projectDir; + } + + public function getRootDir(): string + { + return $this->getProjectDir(); + } +}