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

Added support for optionally tagging hosts #209

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/Deployment/Host.php
Expand Up @@ -68,6 +68,13 @@ class Host
*/
private $connectionOptions;

/**
* The array with the tags of this host.
*
* @var array
*/
private $tags;

/**
* The connection instance used to connect to and communicate with this Host.
*
Expand All @@ -83,10 +90,11 @@ class Host
* @param string $hostname
* @param string $path
* @param array $connectionOptions
* @param array $tags
*
* @throws UnexpectedValueException when $stage is not a valid type
*/
public function __construct($stage, $connectionType, $hostname, $path, array $connectionOptions = array())
public function __construct($stage, $connectionType, $hostname, $path, array $connectionOptions = array(), array $tags = array())
{
if (self::isValidStage($stage) === false) {
throw new UnexpectedValueException(sprintf("'%s' is not a valid stage.", $stage));
Expand All @@ -97,6 +105,7 @@ public function __construct($stage, $connectionType, $hostname, $path, array $co
$this->hostname = $hostname;
$this->path = $path;
$this->connectionOptions = $connectionOptions;
$this->tags = $tags;
}

/**
Expand Down Expand Up @@ -190,4 +199,16 @@ public static function isValidStage($stage)
{
return in_array($stage, array(self::STAGE_TEST, self::STAGE_ACCEPTANCE, self::STAGE_PRODUCTION));
}

/**
* Tests if this host has $tag.
*
* @param string $tag
*
* @return bool
*/
public function hasTag($tag)
{
return in_array($tag, $this->tags);
}
}
3 changes: 3 additions & 0 deletions src/Resources/accompli-schema.json
Expand Up @@ -31,6 +31,9 @@
"additionalProperties": true,
"properties": {
}
},
"tags": {
"type": "array"
}
},
"required": ["stage", "connectionType", "hostname", "path"]
Expand Down
15 changes: 15 additions & 0 deletions tests/Configuration/ConfigurationTest.php
Expand Up @@ -78,6 +78,21 @@ public function testLoadWithExtendedConfiguration()
$this->assertArrayHasKey('deployment', $configuration->toArray());
}

/**
* Tests if Configuration::load imports the configuration with tagged hosts.
*/
public function testLoadWithTaggedHosts()
{
$configuration = new Configuration();
$configuration->load(__DIR__.'/../Resources/accompli-tagged-hosts.json');

$config = $configuration->toArray();

$this->assertArrayHasKey('hosts', $config);
$this->assertEquals(1, count($config['hosts']));
$this->assertArrayHasKey('tags', $config['hosts'][0]);
}

/**
* Tests if Configuration::load imports the configuration extend through the accompli stream wrapper.
*/
Expand Down
15 changes: 13 additions & 2 deletions tests/Deployment/HostTest.php
Expand Up @@ -100,6 +100,17 @@ public function testIsValidStage($stage, $expectedResult)
$this->assertSame($expectedResult, Host::isValidStage($stage));
}

/**
* Tests the hasTag method.
*/
public function testHasTag()
{
$host = $this->createHostInstance(Host::STAGE_TEST, 'local', 'localhost', '/var/www', array(), array('foo'));

$this->assertTrue($host->hasTag('foo'));
$this->assertFalse($host->hasTag('bar'));
}

/**
* Returns an array with testvalues for testGetterMethods.
*
Expand Down Expand Up @@ -141,8 +152,8 @@ public function provideTestIsValidStage()
*
* @return Host
*/
private function createHostInstance($stage = Host::STAGE_TEST, $connectionType = 'local', $hostname = 'localhost', $path = '/var/www', $connectionOptions = array('connectionOptionKey' => 'connectionOptionValue'))
private function createHostInstance($stage = Host::STAGE_TEST, $connectionType = 'local', $hostname = 'localhost', $path = '/var/www', $connectionOptions = array('connectionOptionKey' => 'connectionOptionValue'), $tags = array())
{
return new Host($stage, $connectionType, $hostname, $path, $connectionOptions);
return new Host($stage, $connectionType, $hostname, $path, $connectionOptions, $tags);
}
}
28 changes: 28 additions & 0 deletions tests/Resources/accompli-tagged-hosts.json
@@ -0,0 +1,28 @@
{
"hosts": [
{
"stage": "test",
"connectionType": "local",
"hostname": "",
"path": "",
"tags": ["foo", "bar"]
}
],
"events": {
"subscribers": [
"SetupTask",
{
"class": "ComposerTask",
"options": [
"ignore-platform-reqs"
]
}
],
"listeners": {
"accompli.prepare_server": ["SomeTask::someAction"]
}
},
"deployment": {
"strategy": ""
}
}