Merge pull request #290 from ZeeCoder/feature/auto-server-env-vars

Refactored PR based on #272 (automatic setting of the "server" env var)
This commit is contained in:
Anton Medvedev 2015-05-25 09:13:07 +07:00
commit 06c958f5c4
2 changed files with 34 additions and 5 deletions

View File

@ -27,6 +27,12 @@ class Builder
{
$this->config = $config;
$this->env = $env;
$env->setAsProtected('server', [
'name' => $config->getName(),
'host' => $config->getHost(),
'port' => $config->getPort(),
]);
}
/**

View File

@ -112,11 +112,34 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
{
$config = $this->getMockBuilder('Deployer\Server\Configuration')->disableOriginalConstructor()->getMock();
$env = $this->getMock('Deployer\Server\Environment');
$env->expects($this->once())
// Configuring stubs
$config
->method('getName')
->will($this->returnValue('test-name'));
$config
->method('getHost')
->will($this->returnValue('test-host'));
$config
->method('getPort')
->will($this->returnValue(22));
// The Builder class should create the server env variable.
$env->expects($this->at(0))
->method('setAsProtected')
->with('server', [
'name' => 'test-name',
'host' => 'test-host',
'port' => 22,
])
->will($this->returnSelf());
// The `env` method of the Builder class should internally call the
// Environment's `set` method.
$env->expects($this->at(1))
->method('set')
->with('name', 'value')
->will($this->returnSelf());
$b = new Builder($config, $env);
$b->env('name', 'value');
}