From 9df8e51501cce65c7b259f4644663aa0476c9501 Mon Sep 17 00:00:00 2001 From: matlec Date: Fri, 30 May 2025 13:06:20 +0200 Subject: [PATCH 1/9] Fix `ContainerDebugCommandTest::testNoDumpedXML` --- Tests/Functional/ContainerDebugCommandTest.php | 2 +- Tests/Functional/app/ContainerDebug/no_dump.yml | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 Tests/Functional/app/ContainerDebug/no_dump.yml diff --git a/Tests/Functional/ContainerDebugCommandTest.php b/Tests/Functional/ContainerDebugCommandTest.php index 24c6faf33..291a67cb8 100644 --- a/Tests/Functional/ContainerDebugCommandTest.php +++ b/Tests/Functional/ContainerDebugCommandTest.php @@ -53,7 +53,7 @@ public function testNoDebug() public function testNoDumpedXML() { - static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'config.yml', 'debug' => true, 'debug.container.dump' => false]); + static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'no_dump.yml', 'debug' => true]); $application = new Application(static::$kernel); $application->setAutoExit(false); diff --git a/Tests/Functional/app/ContainerDebug/no_dump.yml b/Tests/Functional/app/ContainerDebug/no_dump.yml new file mode 100644 index 000000000..a9c709e9a --- /dev/null +++ b/Tests/Functional/app/ContainerDebug/no_dump.yml @@ -0,0 +1,5 @@ +imports: + - { resource: config.yml } + +parameters: + debug.container.dump: false From 35a2a545f553c30c4679d3797456f82f3d77e08c Mon Sep 17 00:00:00 2001 From: Carlos Quintana Date: Tue, 27 May 2025 14:57:57 +0200 Subject: [PATCH 2/9] [FrameworkBundle] ensureKernelShutdown in tearDownAfterClass --- Test/KernelTestCase.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Test/KernelTestCase.php b/Test/KernelTestCase.php index ee67fa7af..e87ac4824 100644 --- a/Test/KernelTestCase.php +++ b/Test/KernelTestCase.php @@ -11,6 +11,7 @@ namespace Symfony\Bundle\FrameworkBundle\Test; +use PHPUnit\Framework\Attributes\AfterClass; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -120,8 +121,11 @@ protected static function createKernel(array $options = []): KernelInterface /** * Shuts the kernel down if it was used in the test - called by the tearDown method by default. + * + * @afterClass */ - protected static function ensureKernelShutdown() + #[AfterClass] + public static function ensureKernelShutdown() { if (null !== static::$kernel) { static::$kernel->boot(); From fe8367b6b3593e5451e419c00afd7e780cfce647 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 4 Jun 2025 15:57:42 +0200 Subject: [PATCH 3/9] Revert "bug #60564 [FrameworkBundle] ensureKernelShutdown in tearDownAfterClass (cquintana92)" This reverts commit ec76ab4f28454ebfbcf14287b2aac1351f00df79, reversing changes made to bc886008906f022a8fbf9796b943af928b64d86c. --- Test/KernelTestCase.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Test/KernelTestCase.php b/Test/KernelTestCase.php index e87ac4824..ee67fa7af 100644 --- a/Test/KernelTestCase.php +++ b/Test/KernelTestCase.php @@ -11,7 +11,6 @@ namespace Symfony\Bundle\FrameworkBundle\Test; -use PHPUnit\Framework\Attributes\AfterClass; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -121,11 +120,8 @@ protected static function createKernel(array $options = []): KernelInterface /** * Shuts the kernel down if it was used in the test - called by the tearDown method by default. - * - * @afterClass */ - #[AfterClass] - public static function ensureKernelShutdown() + protected static function ensureKernelShutdown() { if (null !== static::$kernel) { static::$kernel->boot(); From 26ca2357cab5dfe862f2bbf397bd1459a8901af8 Mon Sep 17 00:00:00 2001 From: Carlos Quintana Date: Tue, 27 May 2025 14:57:57 +0200 Subject: [PATCH 4/9] [FrameworkBundle] ensureKernelShutdown in tearDownAfterClass --- Test/KernelTestCase.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Test/KernelTestCase.php b/Test/KernelTestCase.php index ee67fa7af..1312f6592 100644 --- a/Test/KernelTestCase.php +++ b/Test/KernelTestCase.php @@ -45,6 +45,14 @@ protected function tearDown(): void static::$booted = false; } + public static function tearDownAfterClass(): void + { + static::ensureKernelShutdown(); + static::$class = null; + static::$kernel = null; + static::$booted = false; + } + /** * @throws \RuntimeException * @throws \LogicException From 4e7ea17b45e01c02d2462901ef2eeab252237e0a Mon Sep 17 00:00:00 2001 From: Jack Worman Date: Thu, 12 Jun 2025 13:41:08 -0400 Subject: [PATCH 5/9] Fix-type-error-when-revealing-broken-secret --- Command/SecretsRevealCommand.php | 4 ++++ Secrets/AbstractVault.php | 3 +++ Secrets/DotenvVault.php | 4 ++-- Tests/Command/SecretsRevealCommandTest.php | 13 +++++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Command/SecretsRevealCommand.php b/Command/SecretsRevealCommand.php index 150186b1d..c2110ee76 100644 --- a/Command/SecretsRevealCommand.php +++ b/Command/SecretsRevealCommand.php @@ -61,6 +61,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int if (!\array_key_exists($name, $secrets)) { $io->error(\sprintf('The secret "%s" does not exist.', $name)); + return self::INVALID; + } elseif (null === $secrets[$name]) { + $io->error(\sprintf('The secret "%s" could not be decrypted.', $name)); + return self::INVALID; } diff --git a/Secrets/AbstractVault.php b/Secrets/AbstractVault.php index 882ec7862..788601d2e 100644 --- a/Secrets/AbstractVault.php +++ b/Secrets/AbstractVault.php @@ -31,6 +31,9 @@ abstract public function reveal(string $name): ?string; abstract public function remove(string $name): bool; + /** + * @return array + */ abstract public function list(bool $reveal = false): array; protected function validateName(string $name): void diff --git a/Secrets/DotenvVault.php b/Secrets/DotenvVault.php index 15952611a..3fab5f4e2 100644 --- a/Secrets/DotenvVault.php +++ b/Secrets/DotenvVault.php @@ -89,13 +89,13 @@ public function list(bool $reveal = false): array foreach ($_ENV as $k => $v) { if ('' !== ($v ?? '') && preg_match('/^\w+$/D', $k)) { - $secrets[$k] = $reveal ? $v : null; + $secrets[$k] = \is_string($v) && $reveal ? $v : null; } } foreach ($_SERVER as $k => $v) { if ('' !== ($v ?? '') && preg_match('/^\w+$/D', $k)) { - $secrets[$k] = $reveal ? $v : null; + $secrets[$k] = \is_string($v) && $reveal ? $v : null; } } diff --git a/Tests/Command/SecretsRevealCommandTest.php b/Tests/Command/SecretsRevealCommandTest.php index 94643db2c..d77d303d5 100644 --- a/Tests/Command/SecretsRevealCommandTest.php +++ b/Tests/Command/SecretsRevealCommandTest.php @@ -46,6 +46,19 @@ public function testInvalidName() $this->assertStringContainsString('The secret "undefinedKey" does not exist.', trim($tester->getDisplay(true))); } + public function testFailedDecrypt() + { + $vault = $this->createMock(AbstractVault::class); + $vault->method('list')->willReturn(['secretKey' => null]); + + $command = new SecretsRevealCommand($vault); + + $tester = new CommandTester($command); + $this->assertSame(Command::INVALID, $tester->execute(['name' => 'secretKey'])); + + $this->assertStringContainsString('The secret "secretKey" could not be decrypted.', trim($tester->getDisplay(true))); + } + /** * @backupGlobals enabled */ From e06d87953e87342ac936be939c496712ab9ef6e8 Mon Sep 17 00:00:00 2001 From: rhel-eo Date: Thu, 5 Jun 2025 10:54:16 +0100 Subject: [PATCH 6/9] [FrameworkBundle] Fix allow `loose` as an email validation mode --- DependencyInjection/Configuration.php | 2 +- Tests/DependencyInjection/PhpFrameworkExtensionTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index bae8967a8..6bed89cf1 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -1067,7 +1067,7 @@ private function addValidationSection(ArrayNodeDefinition $rootNode, callable $e ->validate()->castToArray()->end() ->end() ->scalarNode('translation_domain')->defaultValue('validators')->end() - ->enumNode('email_validation_mode')->values((class_exists(Email::class) ? Email::VALIDATION_MODES : ['html5-allow-no-tld', 'html5', 'strict']) + ['loose'])->end() + ->enumNode('email_validation_mode')->values(array_merge(class_exists(Email::class) ? Email::VALIDATION_MODES : ['html5-allow-no-tld', 'html5', 'strict'], ['loose']))->end() ->arrayNode('mapping') ->addDefaultsIfNotSet() ->fixXmlConfig('path') diff --git a/Tests/DependencyInjection/PhpFrameworkExtensionTest.php b/Tests/DependencyInjection/PhpFrameworkExtensionTest.php index e5cc8522a..bd455d648 100644 --- a/Tests/DependencyInjection/PhpFrameworkExtensionTest.php +++ b/Tests/DependencyInjection/PhpFrameworkExtensionTest.php @@ -272,5 +272,6 @@ public static function emailValidationModeProvider() foreach (Email::VALIDATION_MODES as $mode) { yield [$mode]; } + yield ['loose']; } } From 9064cf54d1435b9b3c1f5b3dd39b9933d7074f2f Mon Sep 17 00:00:00 2001 From: Max Baldanza Date: Fri, 13 Jun 2025 10:34:24 +0100 Subject: [PATCH 7/9] [FrameworkBundle] Fix argument not provided to `add_bus_name_stamp_middleware` The bus name only gets provided to `add_bus_name_stamp_middleware` if using the default middlewares meaning that if you want to define the middlewares yourself then you need to define this service or you get an error: `Too few arguments to function Symfony\Component\Messenger\Middleware\AddBusNameStampMiddleware::__construct(), 0 passed` --- DependencyInjection/FrameworkExtension.php | 10 ++++---- .../Fixtures/php/messenger_bus_name_stamp.php | 24 +++++++++++++++++++ .../Fixtures/xml/messenger_bus_name_stamp.xml | 20 ++++++++++++++++ .../Fixtures/yml/messenger_bus_name_stamp.yml | 17 +++++++++++++ .../FrameworkExtensionTestCase.php | 22 +++++++++++++++++ 5 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 Tests/DependencyInjection/Fixtures/php/messenger_bus_name_stamp.php create mode 100644 Tests/DependencyInjection/Fixtures/xml/messenger_bus_name_stamp.xml create mode 100644 Tests/DependencyInjection/Fixtures/yml/messenger_bus_name_stamp.yml diff --git a/DependencyInjection/FrameworkExtension.php b/DependencyInjection/FrameworkExtension.php index 68386120e..40834b385 100644 --- a/DependencyInjection/FrameworkExtension.php +++ b/DependencyInjection/FrameworkExtension.php @@ -2214,16 +2214,18 @@ private function registerMessengerConfiguration(array $config, ContainerBuilder $defaultMiddleware['after'][0]['arguments'] = [$bus['default_middleware']['allow_no_senders']]; $defaultMiddleware['after'][1]['arguments'] = [$bus['default_middleware']['allow_no_handlers']]; - // argument to add_bus_name_stamp_middleware - $defaultMiddleware['before'][0]['arguments'] = [$busId]; - $middleware = array_merge($defaultMiddleware['before'], $middleware, $defaultMiddleware['after']); } - foreach ($middleware as $middlewareItem) { + foreach ($middleware as $key => $middlewareItem) { if (!$validationEnabled && \in_array($middlewareItem['id'], ['validation', 'messenger.middleware.validation'], true)) { throw new LogicException('The Validation middleware is only available when the Validator component is installed and enabled. Try running "composer require symfony/validator".'); } + + // argument to add_bus_name_stamp_middleware + if ('add_bus_name_stamp_middleware' === $middlewareItem['id']) { + $middleware[$key]['arguments'] = [$busId]; + } } if ($container->getParameter('kernel.debug') && class_exists(Stopwatch::class)) { diff --git a/Tests/DependencyInjection/Fixtures/php/messenger_bus_name_stamp.php b/Tests/DependencyInjection/Fixtures/php/messenger_bus_name_stamp.php new file mode 100644 index 000000000..5c9c3c310 --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/php/messenger_bus_name_stamp.php @@ -0,0 +1,24 @@ +loadFromExtension('framework', [ + 'annotations' => false, + 'http_method_override' => false, + 'handle_all_throwables' => true, + 'php_errors' => ['log' => true], + 'messenger' => [ + 'default_bus' => 'messenger.bus.commands', + 'buses' => [ + 'messenger.bus.commands' => [ + 'default_middleware' => false, + 'middleware' => [ + 'add_bus_name_stamp_middleware', + 'send_message', + 'handle_message', + ], + ], + 'messenger.bus.events' => [ + 'default_middleware' => true, + ], + ], + ], +]); diff --git a/Tests/DependencyInjection/Fixtures/xml/messenger_bus_name_stamp.xml b/Tests/DependencyInjection/Fixtures/xml/messenger_bus_name_stamp.xml new file mode 100644 index 000000000..bef24ed53 --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/xml/messenger_bus_name_stamp.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + diff --git a/Tests/DependencyInjection/Fixtures/yml/messenger_bus_name_stamp.yml b/Tests/DependencyInjection/Fixtures/yml/messenger_bus_name_stamp.yml new file mode 100644 index 000000000..954c66ae9 --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/yml/messenger_bus_name_stamp.yml @@ -0,0 +1,17 @@ +framework: + annotations: false + http_method_override: false + handle_all_throwables: true + php_errors: + log: true + messenger: + default_bus: messenger.bus.commands + buses: + messenger.bus.commands: + default_middleware: false + middleware: + - "add_bus_name_stamp_middleware" + - "send_message" + - "handle_message" + messenger.bus.events: + default_middleware: true diff --git a/Tests/DependencyInjection/FrameworkExtensionTestCase.php b/Tests/DependencyInjection/FrameworkExtensionTestCase.php index 7f94b83ce..11dd7e848 100644 --- a/Tests/DependencyInjection/FrameworkExtensionTestCase.php +++ b/Tests/DependencyInjection/FrameworkExtensionTestCase.php @@ -1102,6 +1102,28 @@ public function testMessengerWithMultipleBuses() $this->assertSame('messenger.bus.commands', (string) $container->getAlias('messenger.default_bus')); } + public function testMessengerWithAddBusNameStampMiddleware() + { + $container = $this->createContainerFromFile('messenger_bus_name_stamp'); + + $this->assertTrue($container->has('messenger.bus.commands')); + $this->assertEquals([ + ['id' => 'add_bus_name_stamp_middleware', 'arguments' => ['messenger.bus.commands']], + ['id' => 'send_message', 'arguments' => []], + ['id' => 'handle_message', 'arguments' => []], + ], $container->getParameter('messenger.bus.commands.middleware')); + $this->assertTrue($container->has('messenger.bus.events')); + $this->assertSame([], $container->getDefinition('messenger.bus.events')->getArgument(0)); + $this->assertEquals([ + ['id' => 'add_bus_name_stamp_middleware', 'arguments' => ['messenger.bus.events']], + ['id' => 'reject_redelivered_message_middleware'], + ['id' => 'dispatch_after_current_bus'], + ['id' => 'failed_message_processing_middleware'], + ['id' => 'send_message', 'arguments' => [true]], + ['id' => 'handle_message', 'arguments' => [false]], + ], $container->getParameter('messenger.bus.events.middleware')); + } + public function testMessengerMiddlewareFactoryErroneousFormat() { $this->expectException(\InvalidArgumentException::class); From ff892d3ab4b8aa35921bc2120a4b31d57948fe22 Mon Sep 17 00:00:00 2001 From: Gregor Harlan Date: Thu, 26 Jun 2025 22:46:07 +0200 Subject: [PATCH 8/9] Fix command option mode (InputOption::VALUE_REQUIRED) --- Command/TranslationDebugCommand.php | 2 +- Command/TranslationUpdateCommand.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Command/TranslationDebugCommand.php b/Command/TranslationDebugCommand.php index ecb0ad8d7..53ee1949f 100644 --- a/Command/TranslationDebugCommand.php +++ b/Command/TranslationDebugCommand.php @@ -79,7 +79,7 @@ protected function configure(): void ->setDefinition([ new InputArgument('locale', InputArgument::REQUIRED, 'The locale'), new InputArgument('bundle', InputArgument::OPTIONAL, 'The bundle name or directory where to load the messages'), - new InputOption('domain', null, InputOption::VALUE_OPTIONAL, 'The messages domain'), + new InputOption('domain', null, InputOption::VALUE_REQUIRED, 'The messages domain'), new InputOption('only-missing', null, InputOption::VALUE_NONE, 'Display only missing messages'), new InputOption('only-unused', null, InputOption::VALUE_NONE, 'Display only unused messages'), new InputOption('all', null, InputOption::VALUE_NONE, 'Load messages from all registered bundles'), diff --git a/Command/TranslationUpdateCommand.php b/Command/TranslationUpdateCommand.php index f8ce99c41..259027ce0 100644 --- a/Command/TranslationUpdateCommand.php +++ b/Command/TranslationUpdateCommand.php @@ -84,14 +84,14 @@ protected function configure(): void ->setDefinition([ new InputArgument('locale', InputArgument::REQUIRED, 'The locale'), new InputArgument('bundle', InputArgument::OPTIONAL, 'The bundle name or directory where to load the messages'), - new InputOption('prefix', null, InputOption::VALUE_OPTIONAL, 'Override the default prefix', '__'), - new InputOption('format', null, InputOption::VALUE_OPTIONAL, 'Override the default output format', 'xlf12'), + new InputOption('prefix', null, InputOption::VALUE_REQUIRED, 'Override the default prefix', '__'), + new InputOption('format', null, InputOption::VALUE_REQUIRED, 'Override the default output format', 'xlf12'), new InputOption('dump-messages', null, InputOption::VALUE_NONE, 'Should the messages be dumped in the console'), new InputOption('force', null, InputOption::VALUE_NONE, 'Should the extract be done'), new InputOption('clean', null, InputOption::VALUE_NONE, 'Should clean not found messages'), - new InputOption('domain', null, InputOption::VALUE_OPTIONAL, 'Specify the domain to extract'), + new InputOption('domain', null, InputOption::VALUE_REQUIRED, 'Specify the domain to extract'), new InputOption('sort', null, InputOption::VALUE_OPTIONAL, 'Return list of messages sorted alphabetically (only works with --dump-messages)', 'asc'), - new InputOption('as-tree', null, InputOption::VALUE_OPTIONAL, 'Dump the messages as a tree-like structure: The given value defines the level where to switch to inline YAML'), + new InputOption('as-tree', null, InputOption::VALUE_REQUIRED, 'Dump the messages as a tree-like structure: The given value defines the level where to switch to inline YAML'), ]) ->setHelp(<<<'EOF' The %command.name% command extracts translation strings from templates From 89a21b5fc1e5c698712b70724af41416aa1109ae Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 27 Jun 2025 21:54:19 +0200 Subject: [PATCH 9/9] - --- Command/TranslationUpdateCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Command/TranslationUpdateCommand.php b/Command/TranslationUpdateCommand.php index b6cc23839..25fd1c91e 100644 --- a/Command/TranslationUpdateCommand.php +++ b/Command/TranslationUpdateCommand.php @@ -81,7 +81,7 @@ protected function configure(): void new InputOption('force', null, InputOption::VALUE_NONE, 'Should the extract be done'), new InputOption('clean', null, InputOption::VALUE_NONE, 'Should clean not found messages'), new InputOption('domain', null, InputOption::VALUE_REQUIRED, 'Specify the domain to extract'), - new InputOption('sort', null, InputOption::VALUE_OPTIONAL, 'Return list of messages sorted alphabetically'), + new InputOption('sort', null, InputOption::VALUE_REQUIRED, 'Return list of messages sorted alphabetically'), new InputOption('as-tree', null, InputOption::VALUE_REQUIRED, 'Dump the messages as a tree-like structure: The given value defines the level where to switch to inline YAML'), ]) ->setHelp(<<<'EOF'