Skip to content

Commit

Permalink
[AdminBundle] Deprecate new_authentication enable config
Browse files Browse the repository at this point in the history
  • Loading branch information
acrobat committed Oct 25, 2021
1 parent 93160fd commit eda712c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
24 changes: 23 additions & 1 deletion src/Kunstmaan/AdminBundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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' => [
Expand All @@ -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' => [
Expand Down Expand Up @@ -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);
}
}

0 comments on commit eda712c

Please sign in to comment.