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

Recursively add configuration options #962

Merged
merged 3 commits into from
Jan 23, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Added option `-L` to `setfacl` [#956](https://github.com/deployphp/deployer/pull/956)
- Run `deploy:unlock` when deploy is fail [#958](https://github.com/deployphp/deployer/pull/958)
- Now throw exception on duplicates in `shared_dirs`
- `add()` now merges configuration options recursively [#962](https://github.com/deployphp/deployer/pull/962)

### Fixed
- Fixed native ssh scp option
Expand Down
2 changes: 1 addition & 1 deletion src/Deployer.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public static function addDefault($name, $array)
if (!is_array($config)) {
throw new \RuntimeException("Configuration parameter `$name` isn't array.");
}
self::setDefault($name, array_merge($config, $array));
self::setDefault($name, array_merge_recursive($config, $array));
} else {
self::setDefault($name, $array);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Server/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function add($name, $array)
if (!is_array($config)) {
throw new \RuntimeException("Configuration parameter `$name` isn't array.");
}
$this->set($name, array_merge($config, $array));
$this->set($name, array_merge_recursive($config, $array));
} else {
$this->set($name, $array);
}
Expand Down
30 changes: 27 additions & 3 deletions test/src/DeployerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,34 @@ public function testSetDefault()

public function testAddDefault()
{
Deployer::setDefault('config', ['one', 'two']);
Deployer::addDefault('config', ['three']);
Deployer::setDefault('config', [
'one',
'two',
'nested' => [],
]);
Deployer::addDefault('config', [
'three',
'nested' => [
'first',
],
]);
Deployer::addDefault('config', [
'nested' => [
'second',
],
]);

$expected = [
'one',
'two',
'three',
'nested' => [
'first',
'second',
],
];

$this->assertEquals(['one', 'two', 'three'], Deployer::getDefault('config'));
$this->assertEquals($expected, Deployer::getDefault('config'));
}

/**
Expand Down
30 changes: 27 additions & 3 deletions test/src/Server/EnvironmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,34 @@ public function testContainingProtectedParam()
public function testAddParams()
{
$env = new Environment();
$env->set('config', ['one', 'two']);
$env->add('config', ['three']);
$env->set('config', [
'one',
'two',
'nested' => [],
]);
$env->add('config', [
'three',
'nested' => [
'first',
],
]);
$env->add('config', [
'nested' => [
'second',
],
]);

$this->assertEquals(['one', 'two', 'three'], $env->get('config'));
$expected = [
'one',
'two',
'three',
'nested' => [
'first',
'second',
],
];

$this->assertEquals($expected, $env->get('config'));
}

/**
Expand Down