Skip to content

Commit

Permalink
Checking blt.yml for Cloud app uuid. (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
grasmash authored Jun 9, 2020
1 parent 08df362 commit 5a3fdbf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Command/CommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
use Symfony\Component\Validator\Constraints\Uuid;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Component\Validator\Validation;
use Symfony\Component\Yaml\Yaml;
use Webmozart\KeyValueStore\JsonFileStore;
use Webmozart\PathUtil\Path;
use Zumba\Amplitude\Amplitude;

/**
Expand Down Expand Up @@ -596,14 +598,23 @@ protected function doDetermineCloudApplication() {
return $application_uuid;
}

// Try blt.yml.
$blt_yaml_file_path = Path::join($this->repoRoot, 'blt', 'blt.yml');
if (file_exists($blt_yaml_file_path)) {
$contents = Yaml::parseFile($blt_yaml_file_path);
if (array_key_exists('cloud', $contents) && array_key_exists('appId', $contents['cloud'])) {
$this->logger->debug('Using Cloud application UUID ' . $contents['cloud']['appId'] . ' from blt/blt.yml');
return $contents['cloud']['appId'];
}
}

// If an IDE, get from env var.
if (self::isAcquiaCloudIde() && $application_uuid = self::getThisCloudIdeCloudAppUuid()) {
return $application_uuid;
}

// Try to guess based on local git url config.
if ($cloud_application = $this->inferCloudAppFromLocalGitConfig($acquia_cloud_client)) {

return $cloud_application->uuid;
}

Expand Down
14 changes: 14 additions & 0 deletions tests/phpunit/src/Commands/Api/ApiCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Acquia\Cli\Command\Api\ApiCommandHelper;
use Acquia\Cli\Tests\CommandTestBase;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Yaml\Yaml;
use Webmozart\PathUtil\Path;

/**
* Class ApiCommandTest.
Expand Down Expand Up @@ -162,6 +164,18 @@ public function testApiCommandDefinitionRequestBody($command_name, $method, $usa
$this->assertStringContainsString($usage, $this->command->getUsages()[0]);
}

public function testGetApplicationUuidFromBltYml(): void {
$mock_body = $this->getMockResponseFromSpec('/applications/{applicationUuid}', 'get', '200');
$this->clientProphecy->request('get', '/applications/' . $mock_body->uuid)->willReturn($mock_body)->shouldBeCalled();
$this->command = $this->getApiCommandByName('api:applications:find');
$blt_config_file_path = Path::join($this->projectFixtureDir, 'blt', 'blt.yml');
$this->fs->dumpFile($blt_config_file_path, Yaml::dump(['cloud' => ['appId' => $mock_body->uuid]]));
$this->executeCommand();
$this->prophet->checkPredictions();
$output = $this->getDisplay();
$this->fs->remove($blt_config_file_path);
}

/**
* @param $name
*
Expand Down

0 comments on commit 5a3fdbf

Please sign in to comment.