8000 bug #53751 [AssetMapper] Improve import_polyfill configuration error … · symfony/symfony@2fcd5be · GitHub
[go: up one dir, main page]

Skip to content

Commit 2fcd5be

Browse files
committed
bug #53751 [AssetMapper] Improve import_polyfill configuration error (smnandre)
This PR was merged into the 6.4 branch. Discussion ---------- [AssetMapper] Improve import_polyfill configuration error | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #53725 | License | MIT Add missing error when 'asset_mapper.importmap_polyfill' is set to true (only false and string are allowed) Commits ------- 050fe20 [AssetMapper] Improve import_polyfill configuration error
2 parents 03ebef7 + 050fe20 commit 2fcd5be

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,10 @@ private function addAssetMapperSection(ArrayNodeDefinition $rootNode, callable $
930930
->end()
931931
->scalarNode('importmap_polyfill')
932932
->info('The importmap name that will be used to load the polyfill. Set to false to disable.')
933+
->validate()
934+
->ifTrue()
935+
->thenInvalid('Invalid "importmap_polyfill" value. Must be either an importmap name or false.')
936+
->end()
933937
->defaultValue('es-module-shims')
934938
->end()
935939
->arrayNode('importmap_script_attributes')

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,42 @@ public function testAssetMapperCanBeEnabled()
143143
$this->assertEquals($defaultConfig, $config['asset_mapper']);
144144
}
145145

146+
/**
147+
* @dataProvider provideImportmapPolyfillTests
148+
*/
149+
public function testAssetMapperPolyfillValue(mixed $polyfillValue, bool $isValid, mixed $expected)
150+
{
151+
$processor = new Processor();
152+
$configuration = new Configuration(true);
153+
154+
if (!$isValid) {
155+
$this->expectException(InvalidConfigurationException::class);
156+
$this->expectExceptionMessage($expected);
157+
}
158+
159+
$config = $processor->processConfiguration($configuration, [[
160+
'http_method_override' => false,
161+
'handle_all_throwables' => true,
162+
'php_errors' => ['log' => true],
163+
'asset_mapper' => null === $polyfillValue ? [] : [
164+
'importmap_polyfill' => $polyfillValue,
165+
],
166+
]]);
167+
168+
if ($isValid) {
169+
$this->assertEquals($expected, $config['asset_mapper']['importmap_polyfill']);
170+
}
171+
}
172+
173+
public static function provideImportmapPolyfillTests()
174+
{
175+
yield [true, false, 'Must be either an importmap name or false.'];
176+
yield [null, true, 'es-module-shims'];
177+
yield ['es-module-shims', true, 'es-module-shims'];
178+
yield ['foo', true, 'foo'];
179+
yield [false, true, false];
180+
}
181+
146182
/**
147183
* @dataProvider provideValidAssetsPackageNameConfigurationTests
148184
*/

0 commit comments

Comments
 (0)
0