Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
Added connection options and adapter implementation to Host
Browse files Browse the repository at this point in the history
  • Loading branch information
niels-nijens committed Oct 18, 2015
1 parent 7488867 commit 9b0309c
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 1 deletion.
49 changes: 48 additions & 1 deletion src/Deployment/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Accompli\Deployment;

use Accompli\Deployment\Connection\ConnectionAdapterInterface;
use UnexpectedValueException;

/**
Expand Down Expand Up @@ -60,17 +61,32 @@ class Host
*/
private $path;

/**
* The array with connection options
*
* @var array
*/
private $connectionOptions;

/**
* The connection instance used to connect to and communicate with this Host.
*
* @var ConnectionAdapterInterface
*/
private $connection;

/**
* Constructs a new Host instance.
*
* @param string $stage
* @param string $connectionType
* @param string $hostname
* @param string $path
* @param array $connectionOptions
*
* @throws UnexpectedValueException when $stage is not a valid type
*/
public function __construct($stage, $connectionType, $hostname, $path)
public function __construct($stage, $connectionType, $hostname, $path, array $connectionOptions = array())
{
if (self::isValidStage($stage) === false) {
throw new UnexpectedValueException(sprintf("'%s' is not a valid stage.", $stage));
Expand All @@ -80,6 +96,17 @@ public function __construct($stage, $connectionType, $hostname, $path)
$this->connectionType = $connectionType;
$this->hostname = $hostname;
$this->path = $path;
$this->connectionOptions = $connectionOptions;
}

/**
* Returns true if this Host has a connection instance
*
* @return ConnectionAdapterInterface
*/
public function hasConnection()
{
return ($this->connection instanceof ConnectionAdapterInterface);
}

/**
Expand Down Expand Up @@ -112,6 +139,16 @@ public function getHostname()
return $this->hostname;
}

/**
* Returns the connection instance.
*
* @return ConnectionAdapterInterface
*/
public function getConnection()
{
return $this->connection;
}

/**
* Returns the base workspace path of this host.
*
Expand All @@ -122,6 +159,16 @@ public function getPath()
return $this->path;
}

/**
* Sets the connection instance.
*
* @param ConnectionAdapterInterface $connection
*/
public function setConnection(ConnectionAdapterInterface $connection)
{
$this->connection = $connection;
}

/**
* Returns true if $stage is a valid stage type.
*
Expand Down
6 changes: 6 additions & 0 deletions src/Resources/accompli-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
},
"path": {
"type": "string"
},
"connectionOptions": {
"type": "object",
"additionalProperties": true,
"properties": {
}
}
},
"required": ["stage", "connectionType", "hostname", "path"]
Expand Down
46 changes: 46 additions & 0 deletions tests/Deployment/HostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,52 @@ public function testGetterMethods($getterMethod, $expectedValue)
$this->assertSame($expectedValue, $host->$getterMethod());
}

/**
* Tests if Host::getConnection returns null when no connection adapter instance has been set.
*/
public function testGetConnectionReturnsNull()
{
$host = $this->createHostInstance();

$this->assertNull($host->getConnection());
}

/**
* Tests if Host::getConnection returns the connection adapter instance set with Host::setConnection.
*/
public function testSetConnectionSetsConnectionAndIsReturnedByGetConnection()
{
$connectionMock = $this->getMockBuilder('Accompli\Deployment\Connection\ConnectionAdapterInterface')->getMock();

$host = $this->createHostInstance();
$host->setConnection($connectionMock);

$this->assertSame($connectionMock, $host->getConnection());
}

/**
* Tests if Host::hasConnection returns false when no connection adapter instance has been set.
*/
public function testHasConnectionReturnsFalse()
{
$host = $this->createHostInstance();

$this->assertFalse($host->hasConnection());
}

/**
* Tests if Host::hasConnection returns true when a connection adapter instance has been set with Host::setConnection.
*/
public function testHasConnectionReturnsTrueWhenConnectionInstanceIsSet()
{
$connectionMock = $this->getMockBuilder('Accompli\Deployment\Connection\ConnectionAdapterInterface')->getMock();

$host = $this->createHostInstance();
$host->setConnection($connectionMock);

$this->assertTrue($host->hasConnection());
}

/**
* testIsValidStage.
*
Expand Down

0 comments on commit 9b0309c

Please sign in to comment.