From aea4f8106aa6dcf484eea12bb1e10c5468ad6488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Mon, 19 Dec 2022 23:14:16 +0100 Subject: [PATCH 1/2] Remove array_search and add test --- DependencyInjection/Configuration.php | 23 +++++++++++++------ .../DependencyInjection/ConfigurationTest.php | 20 +++++++++++++++- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 3f1681e7..093f17cd 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -1015,16 +1015,25 @@ private function addVerbosityLevelSection(ArrayNodeDefinition $handerNode) ->ifArray() ->then(function ($v) { $map = []; - $verbosities = ['VERBOSITY_QUIET', 'VERBOSITY_NORMAL', 'VERBOSITY_VERBOSE', 'VERBOSITY_VERY_VERBOSE', 'VERBOSITY_DEBUG']; - $verbosityConstants = [OutputInterface::VERBOSITY_QUIET, OutputInterface::VERBOSITY_NORMAL, OutputInterface::VERBOSITY_VERBOSE, OutputInterface::VERBOSITY_VERY_VERBOSE, OutputInterface::VERBOSITY_DEBUG]; - // allow numeric indexed array with ascending verbosity and lowercase names of the constants + $verbosities = [ + // allow numeric indexed array with ascending verbosity + 0 => 'VERBOSITY_QUIET', + 1 => 'VERBOSITY_NORMAL', + 2 => 'VERBOSITY_VERBOSE', + 3 => 'VERBOSITY_VERY_VERBOSE', + 4 => 'VERBOSITY_DEBUG', + // or array indexed by verbosity constants + OutputInterface::VERBOSITY_QUIET => 'VERBOSITY_QUIET', + OutputInterface::VERBOSITY_NORMAL => 'VERBOSITY_NORMAL', + OutputInterface::VERBOSITY_VERBOSE => 'VERBOSITY_VERBOSE', + OutputInterface::VERBOSITY_VERY_VERBOSE => 'VERBOSITY_VERY_VERBOSE', + OutputInterface::VERBOSITY_DEBUG => 'VERBOSITY_DEBUG', + ]; foreach ($v as $verbosity => $level) { if (is_int($verbosity) && isset($verbosities[$verbosity])) { - $map[$verbosities[$verbosity]] = strtoupper($level); - } elseif (is_int($verbosity) && false !== $i = \array_search($verbosity, $verbosityConstants, true)) { - $map[$verbosities[$i]] = strtoupper($level); + $map[$verbosities[$verbosity]] = $level; } else { - $map[strtoupper($verbosity)] = strtoupper($level); + $map[strtoupper($verbosity)] = $level; } } diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php index d0cb9b88..f89637c1 100644 --- a/Tests/DependencyInjection/ConfigurationTest.php +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -305,10 +305,28 @@ public function provideConsoleHandlerCases(): iterable OutputInterface::VERBOSITY_DEBUG => Logger::DEBUG ] ]; + + yield 'with numeric index' => [ + [ + LOGGER::ALERT, + LOGGER::ERROR, + LOGGER::WARNING, + LOGGER::NOTICE, + LOGGER::INFO, + ], + [ + OutputInterface::VERBOSITY_QUIET => Logger::ALERT, + OutputInterface::VERBOSITY_NORMAL => Logger::ERROR, + OutputInterface::VERBOSITY_VERBOSE => Logger::WARNING, + OutputInterface::VERBOSITY_VERY_VERBOSE => Logger::NOTICE, + OutputInterface::VERBOSITY_DEBUG => Logger::INFO, + ] + ]; + yield 'with constants' => [ [ OutputInterface::VERBOSITY_NORMAL => Logger::NOTICE, - 'verbosity_verbose' => 'info', + OutputInterface::VERBOSITY_VERBOSE => 'info', OutputInterface::VERBOSITY_VERY_VERBOSE => Logger::INFO ], [ From 3b2013c60e06e3c5dc0db80e461ce7b48033e0eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Wed, 24 Sep 2025 11:54:58 +0200 Subject: [PATCH 2/2] Revert test change. --- Tests/DependencyInjection/ConfigurationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php index f89637c1..67165104 100644 --- a/Tests/DependencyInjection/ConfigurationTest.php +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -326,7 +326,7 @@ public function provideConsoleHandlerCases(): iterable yield 'with constants' => [ [ OutputInterface::VERBOSITY_NORMAL => Logger::NOTICE, - OutputInterface::VERBOSITY_VERBOSE => 'info', + 'verbosity_verbose' => 'info', OutputInterface::VERBOSITY_VERY_VERBOSE => Logger::INFO ], [