Skip to content

Commit d9befd5

Browse files
committed
Merge branch '7.0' into 7.1
* 7.0: [AssetMapper] Improve import_polyfill configuration error
2 parents 6ccc82d + 87c1e10 commit d9befd5

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

DependencyInjection/Configuration.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,10 @@ private function addAssetMapperSection(ArrayNodeDefinition $rootNode, callable $
902902
->end()
903903
->scalarNode('importmap_polyfill')
904904
->info('The importmap name that will be used to load the polyfill. Set to false to disable.')
905+
->validate()
906+
->ifTrue()
907+
->thenInvalid('Invalid "importmap_polyfill" value. Must be either an importmap name or false.')
908+
->end()
905909
->defaultValue('es-module-shims')
906910
->end()
907911
->arrayNode('importmap_script_attributes')

Tests/DependencyInjection/ConfigurationTest.php

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

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

0 commit comments

Comments
 (0)