Skip to content

Commit

Permalink
bugfix: global options were not correctly overwritten when changing o…
Browse files Browse the repository at this point in the history
…ptions under deployment;
  • Loading branch information
ribeiropaulor committed Jul 7, 2014
1 parent 021103b commit 0de6488
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
4 changes: 4 additions & 0 deletions Server/ServerRegister.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ public function getMergedOptions(ServerInterface $server)
{
$global = $this->getGlobalOptions();
$local = $server->getOptions();
if (isset($local['deployment']) && isset($global['deployment'])) {
$local['deployment'] = array_merge($global['deployment'], $local['deployment']);
}

return array_merge($global, $local);
}
}
38 changes: 23 additions & 15 deletions Tests/Server/ServerRegisterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,20 @@ public function testGetMergedOptionsMergesSuccessfully()
// create a server register
$register = new ServerRegister(new ServerLoader());

$register->addGlobalOption('pre_local_commands', array('pre_local_command global 1', 'pre_local_command global 2'));
$register->addGlobalOption('post_local_commands', array('post_local_command global 1', 'post_local_command global 2'));
$register->addGlobalOption('pre_remote_commands', array('pre_remote_command global 1', 'pre_remote_command global 2'));
$register->addGlobalOption('post_remote_commands', array('post_remote_command global 1', 'post_remote_command global 2'));
$deploymentOptions = array(
'pre_local_commands' => array('pre_local_command global 1', 'pre_local_command global 2'),
'post_local_commands' => array('post_local_command global 1', 'post_local_command global 2'),
'pre_remote_commands' => array('pre_remote_command global 1', 'pre_remote_command global 2'),
'post_remote_commands' => array('post_remote_command global 1', 'post_remote_command global 2')
);
$register->addGlobalOption('deployment', $deploymentOptions);

// create a server
$server = new Server('www.test.com', 'webtest', '/home/vagrant', '123123', 22, array(
'pre_local_commands' => array(
'pre_local_command server specific'
'deployment' => array(
'pre_local_commands' => array(
'pre_local_command server specific'
)
)
));

Expand All @@ -45,14 +50,17 @@ public function testGetMergedOptionsMergesSuccessfully()

$options = $register->getMergedOptions($server);

$this->assertArrayHasKey('pre_local_commands', $options);
$this->assertArrayHasKey('post_local_commands', $options);
$this->assertArrayHasKey('pre_remote_commands', $options);
$this->assertArrayHasKey('post_remote_commands', $options);
$this->assertCount(1, $options['pre_local_commands']);
$this->assertCount(2, $options['post_local_commands']);
$this->assertCount(2, $options['pre_remote_commands']);
$this->assertCount(2, $options['post_remote_commands']);
$this->assertEquals('pre_local_command server specific', $options['pre_local_commands'][0]);
$this->assertArrayHasKey('deployment', $options);

$depOptions = $options['deployment'];
$this->assertArrayHasKey('pre_local_commands', $depOptions, print_r($depOptions, true));
$this->assertArrayHasKey('post_local_commands', $depOptions, print_r($depOptions, true));
$this->assertArrayHasKey('pre_remote_commands', $depOptions, print_r($depOptions, true));
$this->assertArrayHasKey('post_remote_commands', $depOptions, print_r($depOptions, true));
$this->assertCount(1, $depOptions['pre_local_commands'], print_r($depOptions['pre_local_commands'], true));
$this->assertCount(2, $depOptions['post_local_commands'], print_r($depOptions['post_local_commands'], true));
$this->assertCount(2, $depOptions['pre_remote_commands'], print_r($depOptions['pre_remote_commands'], true));
$this->assertCount(2, $depOptions['post_remote_commands'], print_r($depOptions['post_remote_commands'], true));
$this->assertEquals('pre_local_command server specific', $depOptions['pre_local_commands'][0], print_r($depOptions['pre_local_commands'][0], true));
}
}

0 comments on commit 0de6488

Please sign in to comment.