Skip to content

Commit

Permalink
Add test.
Browse files Browse the repository at this point in the history
  • Loading branch information
grasmash committed May 24, 2024
1 parent 88d7906 commit 584eb3d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/Helpers/TelemetryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,7 @@ public function initializeAmplitude(): void {
}
}

private function normalizeAhEnv(): string {
$ah_env = AcquiaDrupalEnvironmentDetector::getAhEnv();
if (AcquiaDrupalEnvironmentDetector::isAcsfEnv()) {
return 'acsf';
}
public static function normalizeAhEnv($ah_env): string {
if (AcquiaDrupalEnvironmentDetector::isAhProdEnv($ah_env)) {
return 'prod';
}
Expand All @@ -127,7 +123,7 @@ private function normalizeAhEnv(): string {
if (AcquiaDrupalEnvironmentDetector::isAhIdeEnv($ah_env)) {

Check warning on line 123 in src/Helpers/TelemetryHelper.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "IfNegation": --- Original +++ New @@ @@ if (AcquiaDrupalEnvironmentDetector::isAhOdeEnv($ah_env)) { return 'ode'; } - if (AcquiaDrupalEnvironmentDetector::isAhIdeEnv($ah_env)) { + if (!AcquiaDrupalEnvironmentDetector::isAhIdeEnv($ah_env)) { return 'ide'; } return $ah_env;
return 'ide';
}
return AcquiaDrupalEnvironmentDetector::getAhEnv();
return $ah_env;
}

/**
Expand All @@ -138,7 +134,7 @@ private function normalizeAhEnv(): string {
private function getTelemetryUserData(): array {
$data = [
'ah_app_uuid' => getenv('AH_APPLICATION_UUID'),
'ah_env' => $this->normalizeAhEnv(),
'ah_env' => $this->normalizeAhEnv(AcquiaDrupalEnvironmentDetector::getAhEnv()),
'ah_group' => AcquiaDrupalEnvironmentDetector::getAhGroup(),
'ah_non_production' => getenv('AH_NON_PRODUCTION'),
'ah_realm' => getenv('AH_REALM'),
Expand Down
19 changes: 19 additions & 0 deletions tests/phpunit/src/Misc/TelemetryHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,24 @@ public function testGetEnvironmentProviderWithoutAnyEnvSet(): void {
// Expect null since no provider environment variables are set.
$this->assertNull(TelemetryHelper::getEnvironmentProvider());
}
public function providerTestAhEnvNormalization(): array {
return [
['prod', 'prod'],
['01live', 'prod'],
['stage', 'stage'],
['stg', 'stage'],
['dev1', 'dev'],
['ode1', 'ode'],
['ide', 'ide'],
];
}

/**
* @dataProvider providerTestAhEnvNormalization
*/
public function testAhEnvNormalization($ah_env, $expected) {
$normalized_ah_env = TelemetryHelper::normalizeAhEnv($ah_env);
$this->assertEquals($expected, $normalized_ah_env);
}

}

0 comments on commit 584eb3d

Please sign in to comment.