From aae6bec2b901c1621e32abbb6bb3a7c992f5a686 Mon Sep 17 00:00:00 2001 From: Hubert Viktor Date: Sun, 24 May 2015 21:33:43 +0200 Subject: [PATCH] Added the 'server' env var to be set automatically, when the Builder class is instantiated. --- src/Server/Builder.php | 10 ++++++++-- test/src/Server/BuilderTest.php | 29 ++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/Server/Builder.php b/src/Server/Builder.php index bb6aefce0..fe55f4d70 100644 --- a/src/Server/Builder.php +++ b/src/Server/Builder.php @@ -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(), + ]); } /** @@ -110,10 +116,10 @@ public function pemFile($pemFile) $this->config->setPemFile($pemFile); return $this; } - + /** * Using forward agent to authentication - * + * * @return $this */ public function forwardAgent() diff --git a/test/src/Server/BuilderTest.php b/test/src/Server/BuilderTest.php index ecaddeceb..a22cc7f99 100644 --- a/test/src/Server/BuilderTest.php +++ b/test/src/Server/BuilderTest.php @@ -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();