-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Track environment provider in telemetry. (#1741)
* Track environment provider in telemetry. * Adding a test. * Fix phpcs. * Catch mutants * Test edge case. * Unset github. * Skip mutation testing for getProviders(). * Updating comments. * Change providers list. * More mutation fixes. * Cleanup * Add ddev and lando. * Change to TestBase. * Remove unused includes * Fix lando and ddev hijacking. * PHPCS ignore. --------- Co-authored-by: Dane Powell <[email protected]>
- Loading branch information
1 parent
50fdfff
commit 12e1dc5
Showing
2 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Acquia\Cli\Tests\Misc; | ||
|
||
use Acquia\Cli\Helpers\TelemetryHelper; | ||
use Acquia\Cli\Tests\TestBase; | ||
|
||
class TelemetryHelperTest extends TestBase { | ||
|
||
const ENV_VAR_DEFAULT_VALUE = 'test'; | ||
|
||
public function tearDown(): void { | ||
parent::tearDown(); | ||
$envVars = []; | ||
foreach ($this->providerTestEnvironmentProvider() as $args) { | ||
$envVars = array_merge($envVars, $args[1]); | ||
} | ||
|
||
TestBase::unsetEnvVars($envVars); | ||
} | ||
|
||
public function unsetGitHubEnvVars(): void { | ||
$providers = TelemetryHelper::getProviders(); | ||
|
||
// Since we actually run our own tests on GitHub, getEnvironmentProvider() will return 'github' unless we unset it. | ||
$github_env_vars = []; | ||
foreach ($providers['github'] as $var) { | ||
$github_env_vars[$var] = self::ENV_VAR_DEFAULT_VALUE; | ||
} | ||
TestBase::unsetEnvVars($github_env_vars); | ||
} | ||
|
||
/** | ||
* @return array<mixed> | ||
*/ | ||
public function providerTestEnvironmentProvider(): array { | ||
$providersList = TelemetryHelper::getProviders(); | ||
$providersArray = []; | ||
foreach ($providersList as $provider => $envVars) { | ||
$env_vars_with_values = []; | ||
foreach ($envVars as $var_name) { | ||
$env_vars_with_values[$var_name] = self::ENV_VAR_DEFAULT_VALUE; | ||
} | ||
$providersArray[] = [$provider, $env_vars_with_values]; | ||
} | ||
|
||
return $providersArray; | ||
} | ||
|
||
/** | ||
* @dataProvider providerTestEnvironmentProvider() | ||
*/ | ||
public function testEnvironmentProvider(string $provider, array $envVars): void { | ||
$this->unsetGitHubEnvVars(); | ||
TestBase::setEnvVars($envVars); | ||
$this->assertEquals($provider, TelemetryHelper::getEnvironmentProvider()); | ||
} | ||
|
||
/** | ||
* Test the getEnvironmentProvider method when no environment provider is detected. | ||
*/ | ||
public function testGetEnvironmentProviderWithoutAnyEnvSet(): void { | ||
$this->unsetGitHubEnvVars(); | ||
|
||
// Expect null since no provider environment variables are set. | ||
$this->assertNull(TelemetryHelper::getEnvironmentProvider()); | ||
} | ||
|
||
} |