Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AssetMapper] Improve import_polyfill configuration error #53751

Merged
merged 1 commit into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down