function FixtureManipulator::addConfig

Modifies the project root's composer.json properties.

Parameters

array $additional_config: The configuration to add.

bool $update_lock: Whether to run composer update --lock. Defaults to FALSE.

See also

\Composer\Command\ConfigCommand

File

core/modules/package_manager/tests/modules/fixture_manipulator/src/FixtureManipulator.php, line 309

Class

FixtureManipulator
Manipulates a test fixture using Composer commands.

Namespace

Drupal\fixture_manipulator

Code

public function addConfig(array $additional_config, bool $update_lock = FALSE) : self {
    if (empty($additional_config)) {
        throw new \InvalidArgumentException('No config to add.');
    }
    if (!$this->committingChanges) {
        $this->queueManipulation('addConfig', func_get_args());
        return $this;
    }
    $clean_value = function ($value) {
        return $value === FALSE ? 'false' : $value;
    };
    foreach ($additional_config as $key => $value) {
        $command = [
            'config',
        ];
        if (is_array($value)) {
            $value = json_encode($value, JSON_UNESCAPED_SLASHES);
            $command[] = '--json';
        }
        else {
            $value = $clean_value($value);
        }
        $command[] = $key;
        $command[] = $value;
        $this->runComposerCommand($command);
    }
    if ($update_lock) {
        $this->runComposerCommand([
            'update',
            '--lock',
        ]);
    }
    return $this;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.