Skip to content

Commit

Permalink
ACMS-3647: Add helper function to get segmented Acquia environment na…
Browse files Browse the repository at this point in the history
…mes. (#84)

* ACMS-3417: Add helper function to get segmented Acquia environment names.

* ACMS-3417: Add tests for getAhEnvGroup method.

* ACMS-3647: Fix static code analysis warnings.

* ACMS-3647: Fix failing tests.

---------

Co-authored-by: Dane Powell <[email protected]>
  • Loading branch information
rajeshreeputra and danepowell authored Jun 27, 2024
1 parent 7be2ef0 commit 8644c92
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 12 deletions.
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@
"acquia/coding-standards": "^2.0.0",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0.0"
},
"conflict": {
"acquia/blt": ">=12.0.0 <13.5.2"
},
"autoload": {
"psr-4": {
"Acquia\\DrupalEnvironmentDetector\\": "src/",
"Acquia\\DrupalEnvironmentDetector\\Tests\\": "tests/"
}
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
},
"sort-packages": true
},
"conflict": {
"acquia/blt": ">=12.0.0 <13.5.2"
},
"extra": {
"branch-alias": {
"dev-main": "1.x-dev"
},
"phpcodesniffer-search-depth": "4"
},
"autoload": {
"psr-4": {
"Acquia\\DrupalEnvironmentDetector\\": "src/",
"Acquia\\DrupalEnvironmentDetector\\Tests\\": "tests/"
}
}
}
33 changes: 33 additions & 0 deletions src/AcquiaDrupalEnvironmentDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,37 @@ public static function isCodeStudioEnv(): bool {
return (bool) (!empty($gitlab_job_id) && !empty($gitlab_token));
}

/**
* Helper function to get environment Group.
*
* @param string $ah_env
* Environment machine name.
*
* @return string
* The environment Group.
*/
public static function getAhEnvGroup(string $ah_env): string {
if (EnvironmentNames::isAhProdEnv($ah_env)) {
return 'prod';
}
elseif (EnvironmentNames::isAhStageEnv($ah_env)) {
return 'stage';
}
elseif (EnvironmentNames::isAhDevEnv($ah_env)) {
return 'dev';
}
elseif (EnvironmentNames::isAhOdeEnv($ah_env)) {
return 'ode';
}
elseif (EnvironmentNames::isAhIdeEnv($ah_env)) {
return 'ide';
}
elseif (self::isAhEnv()) {
return 'other_acquia_env';
}
else {
return 'non_acquia_env';
}
}

}
15 changes: 12 additions & 3 deletions tests/EnvironmentDetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ public function testIsAhOdeEnv($ah_site_env, $expected_env) {
$this::assertEquals($expected_env === 'ode', AcquiaDrupalEnvironmentDetector::isAhOdeEnv());
}

/**
* Tests EnvironmentDetector::isAcquiaLandoEnv().
*/
public function testIsAcquiaLandoEnv() {
putenv("AH_SITE_ENVIRONMENT=LANDO");
$this::assertEquals('lando', AcquiaDrupalEnvironmentDetector::isAcquiaLandoEnv());
}

/**
* Tests EnvironmentDetector::isAcquiaLandoEnv().
*
Expand All @@ -78,9 +86,9 @@ public function testIsAhOdeEnv($ah_site_env, $expected_env) {
*
* @dataProvider providerTestIsEnv
*/
public function testIsAcquiaLandoEnv($ah_site_env, $expected_env) {
public function testGetAhEnvGroup($ah_site_env, $expected_env) {
putenv("AH_SITE_ENVIRONMENT=$ah_site_env");
$this::assertEquals($expected_env === 'lando', AcquiaDrupalEnvironmentDetector::isAcquiaLandoEnv());
$this::assertEquals($expected_env, AcquiaDrupalEnvironmentDetector::getAhEnvGroup($ah_site_env));
}

/**
Expand All @@ -105,7 +113,8 @@ public function providerTestIsEnv() {
['02live', 'prod'],
['ode1', 'ode'],
['ode2', 'ode'],
['LANDO', 'lando'],
['01update', 'other_acquia_env'],
['', 'non_acquia_env'],
];
}

Expand Down

0 comments on commit 8644c92

Please sign in to comment.