Correctly merge boolean flag of allow-plugin config (#10909)
parent
a5fdc00de1
commit
424547bb70
|
@ -34,7 +34,7 @@ class Config
|
|||
public static $defaultConfig = array(
|
||||
'process-timeout' => 300,
|
||||
'use-include-path' => false,
|
||||
'allow-plugins' => null, // null for BC for now, will become array() after July 2022
|
||||
'allow-plugins' => array(),
|
||||
'use-parent-dir' => 'prompt',
|
||||
'preferred-install' => 'dist',
|
||||
'notify-on-install' => true,
|
||||
|
@ -119,11 +119,6 @@ class Config
|
|||
// load defaults
|
||||
$this->config = static::$defaultConfig;
|
||||
|
||||
// TODO after July 2022 remove this and update the default value above in self::$defaultConfig + remove note from 06-config.md
|
||||
if (strtotime('2022-07-01') < time()) {
|
||||
$this->config['allow-plugins'] = array();
|
||||
}
|
||||
|
||||
$this->repositories = static::$defaultRepositories;
|
||||
$this->useEnvironment = (bool) $useEnvironment;
|
||||
$this->baseDir = $baseDir;
|
||||
|
@ -185,7 +180,7 @@ class Config
|
|||
if (in_array($key, array('bitbucket-oauth', 'github-oauth', 'gitlab-oauth', 'gitlab-token', 'http-basic', 'bearer'), true) && isset($this->config[$key])) {
|
||||
$this->config[$key] = array_merge($this->config[$key], $val);
|
||||
$this->setSourceOfConfigValue($val, $key, $source);
|
||||
} elseif (in_array($key, array('allow-plugins'), true) && isset($this->config[$key]) && is_array($this->config[$key])) {
|
||||
} elseif (in_array($key, array('allow-plugins'), true) && isset($this->config[$key]) && is_array($this->config[$key]) && is_array($val)) {
|
||||
// merging $val first to get the local config on top of the global one, then appending the global config,
|
||||
// then merging local one again to make sure the values from local win over global ones for keys present in both
|
||||
$this->config[$key] = array_merge($val, $this->config[$key], $val);
|
||||
|
|
|
@ -371,4 +371,34 @@ class ConfigTest extends TestCase
|
|||
|
||||
$this->assertEquals('COMPOSER_HTACCESS_PROTECT', $result);
|
||||
}
|
||||
|
||||
public function testMergesPluginConfig()
|
||||
{
|
||||
$config = new Config(false);
|
||||
$config->merge(array('config' => array('allow-plugins' => array('some/plugin' => true))));
|
||||
$this->assertEquals(array('some/plugin' => true), $config->get('allow-plugins'));
|
||||
|
||||
$config->merge(array('config' => array('allow-plugins' => array('another/plugin' => true))));
|
||||
$this->assertEquals(array('some/plugin' => true, 'another/plugin' => true), $config->get('allow-plugins'));
|
||||
}
|
||||
|
||||
public function testOverridesGlobalBooleanPluginsConfig()
|
||||
{
|
||||
$config = new Config(false);
|
||||
$config->merge(array('config' => array('allow-plugins' => true)));
|
||||
$this->assertEquals(true, $config->get('allow-plugins'));
|
||||
|
||||
$config->merge(array('config' => array('allow-plugins' => array('another/plugin' => true))));
|
||||
$this->assertEquals(array('another/plugin' => true), $config->get('allow-plugins'));
|
||||
}
|
||||
|
||||
public function testAllowsAllPluginsFromLocalBoolean()
|
||||
{
|
||||
$config = new Config(false);
|
||||
$config->merge(array('config' => array('allow-plugins' => array('some/plugin' => true))));
|
||||
$this->assertEquals(array('some/plugin' => true), $config->get('allow-plugins'));
|
||||
|
||||
$config->merge(array('config' => array('allow-plugins' => true)));
|
||||
$this->assertEquals(true, $config->get('allow-plugins'));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue