Skip to content

Commit

Permalink
Merge pull request #290 from ZeeCoder/feature/auto-server-env-vars
Browse files Browse the repository at this point in the history
Refactored PR based on #272 (automatic setting of the "server" env var)
  • Loading branch information
Anton Medvedev committed May 25, 2015
2 parents 5429b07 + aae6bec commit 06c958f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/Server/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public function __construct(Configuration $config, Environment $env)
{
$this->config = $config;
$this->env = $env;

$env->setAsProtected('server', [
'name' => $config->getName(),
'host' => $config->getHost(),
'port' => $config->getPort(),
]);
}

/**
Expand Down Expand Up @@ -110,10 +116,10 @@ public function pemFile($pemFile)
$this->config->setPemFile($pemFile);
return $this;
}

/**
* Using forward agent to authentication
*
*
* @return $this
*/
public function forwardAgent()
Expand Down
29 changes: 26 additions & 3 deletions test/src/Server/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,38 @@ public function testEnv()
{
$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');
}

public function testForwardAgent()
{
$config = $this->getMockBuilder('Deployer\Server\Configuration')->disableOriginalConstructor()->getMock();
Expand Down

0 comments on commit 06c958f

Please sign in to comment.