diff --git a/src/Command/CommandBase.php b/src/Command/CommandBase.php index f8bf9ea7d..f2b7fa403 100644 --- a/src/Command/CommandBase.php +++ b/src/Command/CommandBase.php @@ -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; /** @@ -596,6 +598,16 @@ 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; @@ -603,7 +615,6 @@ protected function doDetermineCloudApplication() { // Try to guess based on local git url config. if ($cloud_application = $this->inferCloudAppFromLocalGitConfig($acquia_cloud_client)) { - return $cloud_application->uuid; } diff --git a/tests/phpunit/src/Commands/Api/ApiCommandTest.php b/tests/phpunit/src/Commands/Api/ApiCommandTest.php index 2e1dd1e85..34d0ab512 100644 --- a/tests/phpunit/src/Commands/Api/ApiCommandTest.php +++ b/tests/phpunit/src/Commands/Api/ApiCommandTest.php @@ -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. @@ -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 *