1
0
Fork 0

Correctly merge boolean flag of allow-plugin config (#10909)

pull/10921/head
Andreas Schempp 2022-07-01 11:08:35 +02:00 committed by GitHub
parent a5fdc00de1
commit 424547bb70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 7 deletions

View File

@ -34,7 +34,7 @@ class Config
public static $defaultConfig = array( public static $defaultConfig = array(
'process-timeout' => 300, 'process-timeout' => 300,
'use-include-path' => false, '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', 'use-parent-dir' => 'prompt',
'preferred-install' => 'dist', 'preferred-install' => 'dist',
'notify-on-install' => true, 'notify-on-install' => true,
@ -119,11 +119,6 @@ class Config
// load defaults // load defaults
$this->config = static::$defaultConfig; $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->repositories = static::$defaultRepositories;
$this->useEnvironment = (bool) $useEnvironment; $this->useEnvironment = (bool) $useEnvironment;
$this->baseDir = $baseDir; $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])) { 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->config[$key] = array_merge($this->config[$key], $val);
$this->setSourceOfConfigValue($val, $key, $source); $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, // 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 // 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); $this->config[$key] = array_merge($val, $this->config[$key], $val);

View File

@ -371,4 +371,34 @@ class ConfigTest extends TestCase
$this->assertEquals('COMPOSER_HTACCESS_PROTECT', $result); $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'));
}
} }