diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 2494135b6f9f1..29cb4875d2a5d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -930,6 +930,10 @@ private function addAssetMapperSection(ArrayNodeDefinition $rootNode, callable $ ->end() ->scalarNode('importmap_polyfill') ->info('The importmap name that will be used to load the polyfill. Set to false to disable.') + ->validate() + ->ifTrue() + ->thenInvalid('Invalid "importmap_polyfill" value. Must be either an importmap name or false.') + ->end() ->defaultValue('es-module-shims') ->end() ->arrayNode('importmap_script_attributes') diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index 42619d07f3c3b..ca34ce1092e7d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -143,6 +143,42 @@ public function testAssetMapperCanBeEnabled() $this->assertEquals($defaultConfig, $config['asset_mapper']); } + /** + * @dataProvider provideImportmapPolyfillTests + */ + public function testAssetMapperPolyfillValue(mixed $polyfillValue, bool $isValid, mixed $expected) + { + $processor = new Processor(); + $configuration = new Configuration(true); + + if (!$isValid) { + $this->expectException(InvalidConfigurationException::class); + $this->expectExceptionMessage($expected); + } + + $config = $processor->processConfiguration($configuration, [[ + 'http_method_override' => false, + 'handle_all_throwables' => true, + 'php_errors' => ['log' => true], + 'asset_mapper' => null === $polyfillValue ? [] : [ + 'importmap_polyfill' => $polyfillValue, + ], + ]]); + + if ($isValid) { + $this->assertEquals($expected, $config['asset_mapper']['importmap_polyfill']); + } + } + + public static function provideImportmapPolyfillTests() + { + yield [true, false, 'Must be either an importmap name or false.']; + yield [null, true, 'es-module-shims']; + yield ['es-module-shims', true, 'es-module-shims']; + yield ['foo', true, 'foo']; + yield [false, true, false]; + } + /** * @dataProvider provideValidAssetsPackageNameConfigurationTests */