From eda712ce8086a9b2f21dd6f00e546c6c963dd28d Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 24 Oct 2021 17:46:56 +0200 Subject: [PATCH] [AdminBundle] Deprecate new_authentication enable config --- .../DependencyInjection/Configuration.php | 24 ++++++++++- .../DependencyInjection/ConfigurationTest.php | 40 +++++++++++++++++-- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/src/Kunstmaan/AdminBundle/DependencyInjection/Configuration.php b/src/Kunstmaan/AdminBundle/DependencyInjection/Configuration.php index e0e16d6d70..72affb1531 100644 --- a/src/Kunstmaan/AdminBundle/DependencyInjection/Configuration.php +++ b/src/Kunstmaan/AdminBundle/DependencyInjection/Configuration.php @@ -5,6 +5,7 @@ use Kunstmaan\AdminBundle\Entity\Group; use Kunstmaan\AdminBundle\Entity\User; use Kunstmaan\AdminBundle\Service\AuthenticationMailer\SwiftmailerService; +use Symfony\Component\Config\Definition\BaseNode; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; @@ -32,7 +33,11 @@ public function getConfigTreeBuilder() ->arrayNode('authentication') ->addDefaultsIfNotSet() ->children() - ->booleanNode('enable_new_authentication')->defaultTrue()->end() + ->booleanNode('enable_new_authentication') + ->info('When true, the new authentication system will be used. Note: No-Op option since KunstmaanAdminBundle 6.0. Will always be true.') + ->setDeprecated(...$this->getDeprecationParameters('The "%path%.%node%" configuration key has been deprecated, remove it from your config.', '6.1')) + ->defaultTrue() + ->end() ->scalarNode('user_class')->defaultValue(User::class)->end() ->scalarNode('group_class')->defaultValue(Group::class)->end() ->arrayNode('mailer') @@ -107,4 +112,21 @@ public function getConfigTreeBuilder() return $treeBuilder; } + + /** + * Returns the correct deprecation parameters for setDeprecated. + * + * @param string $message + * @param string $version + * + * @return string[] + */ + private function getDeprecationParameters($message, $version): array + { + if (method_exists(BaseNode::class, 'getDeprecation')) { + return ['kunstmaan/admin-bundle', $version, $message]; + } + + return [$message]; + } } diff --git a/src/Kunstmaan/AdminBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Kunstmaan/AdminBundle/Tests/DependencyInjection/ConfigurationTest.php index 351db9459f..051be558c0 100644 --- a/src/Kunstmaan/AdminBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Kunstmaan/AdminBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -9,6 +9,7 @@ use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait; use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; +use Symfony\Component\Config\Definition\BaseNode; use Symfony\Component\Config\Definition\ConfigurationInterface; class ConfigurationTest extends TestCase @@ -45,7 +46,7 @@ class ConfigurationTest extends TestCase 'max_length' => null, ], 'authentication' => [ - 'enable_new_authentication' => false, + 'enable_new_authentication' => true, 'user_class' => User::class, 'group_class' => Group::class, 'mailer' => [ @@ -68,9 +69,6 @@ public function testConfigGeneratesAsExpected() 'multi_language' => true, 'required_locales' => null, 'default_locale' => null, - 'authentication' => [ - 'enable_new_authentication' => true, - ], 'admin_password' => 'l3tM31n!', 'admin_locales' => ['nl'], 'session_security' => [ @@ -108,4 +106,38 @@ public function testConfigGeneratesAsExpected() $this->assertProcessedConfigurationEquals([$array], $expected); } + + /** + * @group legacy + */ + public function testDeprecatedAuthenticationConfig() + { + if (method_exists(BaseNode::class, 'getDeprecation')) { + $this->expectDeprecation('The "kunstmaan_admin.authentication.enable_new_authentication" configuration key has been deprecated, remove it from your config.'); + } else { + //NEXT_MAJOR remove else when symfony 4.4 support is removed + $this->expectDeprecation('The "kunstmaan_admin.authentication.enable_new_authentication" configuration key has been deprecated, remove it from your config.'); + } + + $array = [ + 'website_title' => null, + 'multi_language' => true, + 'required_locales' => null, + 'default_locale' => null, + 'session_security' => [ + 'ip_check' => false, + 'user_agent_check' => false, + ], + 'authentication' => [ + 'enable_new_authentication' => true, + ], + 'default_admin_locale' => 'en', + 'enable_console_exception_listener' => true, + 'menu_items' => [], + 'admin_prefix' => 'admin', + 'admin_firewall_name' => 'main', + ]; + + $this->assertProcessedConfigurationEquals([$array], self::DEFAULT_EXPECTED_CONFIG); + } }