From d40333d77c267ce0b387a646bc5bc092572a541a Mon Sep 17 00:00:00 2001 From: Damien Harper Date: Fri, 9 Dec 2022 00:59:08 +0100 Subject: [PATCH] Fixed middlewares override (#341) --- ...trineProviderConfigurationCompilerPass.php | 14 ++- tests/App/config/packages/doctrine.yaml | 2 +- .../DoctrineMiddlewareCompilerPassTest.php | 110 ------------------ tests/Fixtures/Resources/config/doctrine.yaml | 2 +- 4 files changed, 10 insertions(+), 118 deletions(-) delete mode 100644 tests/DependencyInjection/Compiler/DoctrineMiddlewareCompilerPassTest.php diff --git a/src/DependencyInjection/Compiler/DoctrineProviderConfigurationCompilerPass.php b/src/DependencyInjection/Compiler/DoctrineProviderConfigurationCompilerPass.php index 855674e8..79d5543c 100644 --- a/src/DependencyInjection/Compiler/DoctrineProviderConfigurationCompilerPass.php +++ b/src/DependencyInjection/Compiler/DoctrineProviderConfigurationCompilerPass.php @@ -100,11 +100,13 @@ private function configureDHMiddleware(ContainerBuilder $container, string $enti if (!$container->hasDefinition($configurationName)) { return; } - $configuration = $container->getDefinition($configurationName); - $DHMiddlewareDef = $container->setDefinition( - $connectionName.'.dh_middleware', - new ChildDefinition('doctrine.dbal.dh_middleware') - ); - $configuration->addMethodCall('setMiddlewares', [[$DHMiddlewareDef]]); + + $container + ->setDefinition( + $connectionName.'.dh_middleware', + new ChildDefinition('doctrine.dbal.dh_middleware') + ) + ->addTag('doctrine.middleware') + ; } } diff --git a/tests/App/config/packages/doctrine.yaml b/tests/App/config/packages/doctrine.yaml index e5676fcd..2a6fd3e4 100644 --- a/tests/App/config/packages/doctrine.yaml +++ b/tests/App/config/packages/doctrine.yaml @@ -29,7 +29,7 @@ doctrine: mappings: App: is_bundle: false - type: annotation + type: attribute dir: '%kernel.project_dir%/../../vendor/damienharper/auditor/tests/Provider/Doctrine/Fixtures/Entity/Standard/Blog' prefix: 'DH\Auditor\Tests\Provider\Doctrine\Fixtures\Entity\Standard\Blog' alias: App diff --git a/tests/DependencyInjection/Compiler/DoctrineMiddlewareCompilerPassTest.php b/tests/DependencyInjection/Compiler/DoctrineMiddlewareCompilerPassTest.php deleted file mode 100644 index 2694a9d8..00000000 --- a/tests/DependencyInjection/Compiler/DoctrineMiddlewareCompilerPassTest.php +++ /dev/null @@ -1,110 +0,0 @@ -container->setParameter('kernel.cache_dir', sys_get_temp_dir()); - $this->container->setParameter('kernel.debug', false); - $this->container->setParameter('kernel.bundles', []); - $doctrineConfig = [ - 'dbal' => [ - 'default_connection' => 'default', - 'connections' => [ - 'default' => [], - ], - ], - 'orm' => [ - 'auto_mapping' => true, - ], - ]; - $this->setParameter('doctrine', $doctrineConfig); - - $DHConfig = [ - 'enabled' => true, - 'timezone' => 'UTC', - 'user_provider' => 'dh_auditor.user_provider', - 'security_provider' => 'dh_auditor.security_provider', - 'role_checker' => 'dh_auditor.role_checker', - 'providers' => [ - 'doctrine' => [ - 'table_prefix' => '', - 'table_suffix' => '_audit', - 'ignored_columns' => [ - 0 => 'createdAt', - 1 => 'updatedAt', - ], - 'entities' => [ - Author::class => [ - 'enabled' => true, - ], - Post::class => [ - 'enabled' => true, - ], - Comment::class => [ - 'enabled' => true, - ], - Tag::class => [ - 'enabled' => true, - ], - ], - 'storage_services' => [ - 0 => '@doctrine.orm.default_entity_manager', - ], - 'auditing_services' => [ - 0 => '@doctrine.orm.default_entity_manager', - ], - 'viewer' => true, - 'storage_mapper' => null, - ], - ], - ]; - $this->setParameter('dh_auditor.configuration', $DHConfig); - - $auditorService = new Definition(); - $this->setDefinition(Configuration::class, $auditorService); - $this->container->loadFromExtension('doctrine', $doctrineConfig); - $this->container->loadFromExtension('dh_auditor', $DHConfig); - $this->compile(); - - $this->assertContainerBuilderHasServiceDefinitionWithMethodCall( - 'doctrine.dbal.default_connection.configuration', - 'setMiddlewares', - [[new ChildDefinition('doctrine.dbal.dh_middleware')]] - ); - } - - protected function registerCompilerPass(ContainerBuilder $container): void - { - $this->container->registerExtension(new DoctrineExtension()); - $this->container->registerExtension(new DHAuditorExtension()); - $container->addCompilerPass(new DoctrineProviderConfigurationCompilerPass()); - } -} diff --git a/tests/Fixtures/Resources/config/doctrine.yaml b/tests/Fixtures/Resources/config/doctrine.yaml index abf21526..7fefbab5 100644 --- a/tests/Fixtures/Resources/config/doctrine.yaml +++ b/tests/Fixtures/Resources/config/doctrine.yaml @@ -29,7 +29,7 @@ doctrine: mappings: App: is_bundle: false - type: annotation + type: attribute dir: '%kernel.project_dir%/vendor/damienharper/auditor/tests/Provider/Doctrine/Fixtures/Entity/Standard/Blog' prefix: 'DH\Auditor\Tests\Provider\Doctrine\Fixtures\Entity\Standard\Blog' alias: App