From ad852ff92b100d525578a10e85572c6c979a6719 Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Thu, 23 May 2024 08:26:54 -0400 Subject: [PATCH 01/16] Track environment provider in telemetry. --- src/Helpers/TelemetryHelper.php | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/Helpers/TelemetryHelper.php b/src/Helpers/TelemetryHelper.php index ca921fa2b..eab5c33f9 100644 --- a/src/Helpers/TelemetryHelper.php +++ b/src/Helpers/TelemetryHelper.php @@ -120,6 +120,7 @@ private function getTelemetryUserData(): array { 'ah_non_production' => getenv('AH_NON_PRODUCTION'), 'ah_realm' => getenv('AH_REALM'), 'CI' => getenv('CI'), + 'env_provider' => $this->getEnvironmentProvider(), 'php_version' => PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION, ]; try { @@ -134,6 +135,41 @@ private function getTelemetryUserData(): array { return $data; } + private function getEnvironmentProvider(): ?string { + // Define the environment variables associated with each provider. + $providers = [ + // Assuming Acquia has a specific environment variable, just for example purposes. + 'acquia' => ['ACQUIA_ENVIRONMENT'], + 'bamboo' => ['BAMBOO_BUILDNUMBER'], + 'bitbucket' => ['BITBUCKET_BRANCH'], + 'circleci' => ['CIRCLECI'], + 'codebuild' => ['CODEBUILD_BUILD_ID'], + 'drone' => ['DRONE'], + 'github' => ['GITHUB_ACTIONS'], + 'gitlab' => ['GITLAB_CI'], + 'heroku' => ['HEROKU_TEST_RUN_ID'], + 'jenkins' => ['JENKINS_URL'], + 'octopus' => ['OCTOPUS_DEPLOYMENT_ID'], + 'teamcity' => ['TEAMCITY_VERSION'], + 'travis' => ['TRAVIS'], + ]; + + // Check for an Acquia environment first as it uses a method call rather than getenv. + if (AcquiaDrupalEnvironmentDetector::getAhEnv()) { + return 'acquia'; + } + + // Check for CI/CD environment variables. + foreach ($providers as $provider => $vars) { + foreach ($vars as $var) { + if (getenv($var) !== FALSE) + return $provider; + } + } + + return NULL; + } + private function getUserId(): ?string { $user = $this->getUserData(); if ($user && isset($user['uuid'])) { From d8cb285bc48fd857b8aa2bbd4284c09ee3e8c8d2 Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Thu, 23 May 2024 10:20:19 -0400 Subject: [PATCH 02/16] Adding a test. --- src/Helpers/TelemetryHelper.php | 44 ++++++++------- .../phpunit/src/Misc/TelemetryHelperTest.php | 54 +++++++++++++++++++ 2 files changed, 79 insertions(+), 19 deletions(-) create mode 100644 tests/phpunit/src/Misc/TelemetryHelperTest.php diff --git a/src/Helpers/TelemetryHelper.php b/src/Helpers/TelemetryHelper.php index eab5c33f9..82fd42ead 100644 --- a/src/Helpers/TelemetryHelper.php +++ b/src/Helpers/TelemetryHelper.php @@ -135,31 +135,15 @@ private function getTelemetryUserData(): array { return $data; } - private function getEnvironmentProvider(): ?string { - // Define the environment variables associated with each provider. - $providers = [ - // Assuming Acquia has a specific environment variable, just for example purposes. - 'acquia' => ['ACQUIA_ENVIRONMENT'], - 'bamboo' => ['BAMBOO_BUILDNUMBER'], - 'bitbucket' => ['BITBUCKET_BRANCH'], - 'circleci' => ['CIRCLECI'], - 'codebuild' => ['CODEBUILD_BUILD_ID'], - 'drone' => ['DRONE'], - 'github' => ['GITHUB_ACTIONS'], - 'gitlab' => ['GITLAB_CI'], - 'heroku' => ['HEROKU_TEST_RUN_ID'], - 'jenkins' => ['JENKINS_URL'], - 'octopus' => ['OCTOPUS_DEPLOYMENT_ID'], - 'teamcity' => ['TEAMCITY_VERSION'], - 'travis' => ['TRAVIS'], - ]; + public static function getEnvironmentProvider(): ?string { + $providers = self::getProviders(); // Check for an Acquia environment first as it uses a method call rather than getenv. if (AcquiaDrupalEnvironmentDetector::getAhEnv()) { return 'acquia'; } - // Check for CI/CD environment variables. + // Check for environment variables. foreach ($providers as $provider => $vars) { foreach ($vars as $var) { if (getenv($var) !== FALSE) @@ -216,4 +200,26 @@ private function getDefaultUserData(): array { ]; } + /** + * @return array[] + * An array of providers and their associated environment variables. + */ + public static function getProviders(): array { + // Define the environment variables associated with each provider. + return [ + 'bamboo' => ['BAMBOO_BUILDNUMBER'], + 'bitbucket' => ['BITBUCKET_BRANCH'], + 'circleci' => ['CIRCLECI'], + 'codebuild' => ['CODEBUILD_BUILD_ID'], + 'drone' => ['DRONE'], + 'github' => ['GITHUB_ACTIONS'], + 'gitlab' => ['GITLAB_CI'], + 'heroku' => ['HEROKU_TEST_RUN_ID'], + 'jenkins' => ['JENKINS_URL'], + 'octopus' => ['OCTOPUS_DEPLOYMENT_ID'], + 'teamcity' => ['TEAMCITY_VERSION'], + 'travis' => ['TRAVIS'], + ]; + } + } diff --git a/tests/phpunit/src/Misc/TelemetryHelperTest.php b/tests/phpunit/src/Misc/TelemetryHelperTest.php new file mode 100644 index 000000000..022202fd5 --- /dev/null +++ b/tests/phpunit/src/Misc/TelemetryHelperTest.php @@ -0,0 +1,54 @@ +providerTestEnvironmentProvider() as $args) { + $envVars = array_merge($envVars, $args[1]); + } + + TestBase::unsetEnvVars($envVars); + } + + protected function createCommand(): CommandBase { + return $this->injectCommand(ClearCacheCommand::class); + } + + /** + * @return array[] + */ + 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] = 'test'; + } + $providersArray[] = [$provider, $env_vars_with_values]; + } + + return $providersArray; + } + + /** + * @dataProvider providerTestEnvironmentProvider() + */ + public function testEnvironmentProvider(string $provider, array $envVars): void { + TestBase::setEnvVars($envVars); + $this->assertEquals($provider, TelemetryHelper::getEnvironmentProvider()); + } + +} From b3a1f297c6fefc8217572b266798e699a0ce2ba0 Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Thu, 23 May 2024 10:25:25 -0400 Subject: [PATCH 03/16] Fix phpcs. --- src/Helpers/TelemetryHelper.php | 2 +- tests/phpunit/src/Misc/TelemetryHelperTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Helpers/TelemetryHelper.php b/src/Helpers/TelemetryHelper.php index 82fd42ead..2ee099a71 100644 --- a/src/Helpers/TelemetryHelper.php +++ b/src/Helpers/TelemetryHelper.php @@ -201,7 +201,7 @@ private function getDefaultUserData(): array { } /** - * @return array[] + * @return array * An array of providers and their associated environment variables. */ public static function getProviders(): array { diff --git a/tests/phpunit/src/Misc/TelemetryHelperTest.php b/tests/phpunit/src/Misc/TelemetryHelperTest.php index 022202fd5..0c6dcb173 100644 --- a/tests/phpunit/src/Misc/TelemetryHelperTest.php +++ b/tests/phpunit/src/Misc/TelemetryHelperTest.php @@ -27,7 +27,7 @@ protected function createCommand(): CommandBase { } /** - * @return array[] + * @return array */ public function providerTestEnvironmentProvider(): array { $providersList = TelemetryHelper::getProviders(); From 27eabae6162180f1fc9d5517fe4d9e0c0f974e6d Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Thu, 23 May 2024 10:29:29 -0400 Subject: [PATCH 04/16] Catch mutants --- tests/phpunit/src/Misc/TelemetryHelperTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/phpunit/src/Misc/TelemetryHelperTest.php b/tests/phpunit/src/Misc/TelemetryHelperTest.php index 0c6dcb173..9c66da91c 100644 --- a/tests/phpunit/src/Misc/TelemetryHelperTest.php +++ b/tests/phpunit/src/Misc/TelemetryHelperTest.php @@ -51,4 +51,16 @@ public function testEnvironmentProvider(string $provider, array $envVars): void $this->assertEquals($provider, TelemetryHelper::getEnvironmentProvider()); } + /** + * Test the getEnvironmentProvider method when no environment provider is detected. + */ + public function testGetEnvironmentProviderWithoutAnyEnvSet(): void { + // Ensure no environment variables are set. + $providersList = TelemetryHelper::getProviders(); + TestBase::unsetEnvVars($providersList); + + // Expect null since no provider environment variables are set. + $this->assertNull(TelemetryHelper::getEnvironmentProvider()); + } + } From cc67cfbc3d93ef11d04fcb60ee537ba6b6801a40 Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Thu, 23 May 2024 10:43:03 -0400 Subject: [PATCH 05/16] Test edge case. --- tests/phpunit/src/Misc/TelemetryHelperTest.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tests/phpunit/src/Misc/TelemetryHelperTest.php b/tests/phpunit/src/Misc/TelemetryHelperTest.php index 9c66da91c..2ced48679 100644 --- a/tests/phpunit/src/Misc/TelemetryHelperTest.php +++ b/tests/phpunit/src/Misc/TelemetryHelperTest.php @@ -14,7 +14,7 @@ class TelemetryHelperTest extends CommandTestBase { public function tearDown(): void { parent::tearDown(); - $envVars = []; + $envVars = ['AH_SITE_ENVIRONMENT' => 'test']; foreach ($this->providerTestEnvironmentProvider() as $args) { $envVars = array_merge($envVars, $args[1]); } @@ -55,12 +55,20 @@ public function testEnvironmentProvider(string $provider, array $envVars): void * Test the getEnvironmentProvider method when no environment provider is detected. */ public function testGetEnvironmentProviderWithoutAnyEnvSet(): void { - // Ensure no environment variables are set. - $providersList = TelemetryHelper::getProviders(); - TestBase::unsetEnvVars($providersList); - // Expect null since no provider environment variables are set. $this->assertNull(TelemetryHelper::getEnvironmentProvider()); } + /** + * Test the getEnvironmentProvider method when Acquia environment is detected. + */ + public function testGetEnvironmentProviderWithAcquia(): void { + TestBase::setEnvVars(['AH_SITE_ENVIRONMENT' => 'test']); + + // We need to make sure our mocked method is used. Depending on the implementation, + // this could involve setting it statically or using dependency injection. + // Expect 'acquia' to be returned since Acquia environment is mocked to be present. + $this->assertEquals('acquia', TelemetryHelper::getEnvironmentProvider()); + } + } From a3d82ff8cda56dc30445f305e4362e4e16e048b2 Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Thu, 23 May 2024 10:53:57 -0400 Subject: [PATCH 06/16] Unset github. --- tests/phpunit/src/Misc/TelemetryHelperTest.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/src/Misc/TelemetryHelperTest.php b/tests/phpunit/src/Misc/TelemetryHelperTest.php index 2ced48679..b90ece96e 100644 --- a/tests/phpunit/src/Misc/TelemetryHelperTest.php +++ b/tests/phpunit/src/Misc/TelemetryHelperTest.php @@ -12,6 +12,8 @@ class TelemetryHelperTest extends CommandTestBase { + const ENV_VAR_DEFAULT_VALUE = 'test'; + public function tearDown(): void { parent::tearDown(); $envVars = ['AH_SITE_ENVIRONMENT' => 'test']; @@ -35,7 +37,7 @@ public function providerTestEnvironmentProvider(): array { foreach ($providersList as $provider => $envVars) { $env_vars_with_values = []; foreach ($envVars as $var_name) { - $env_vars_with_values[$var_name] = 'test'; + $env_vars_with_values[$var_name] = self::ENV_VAR_DEFAULT_VALUE; } $providersArray[] = [$provider, $env_vars_with_values]; } @@ -55,6 +57,16 @@ public function testEnvironmentProvider(string $provider, array $envVars): void * Test the getEnvironmentProvider method when no environment provider is detected. */ public function testGetEnvironmentProviderWithoutAnyEnvSet(): 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); + // Expect null since no provider environment variables are set. $this->assertNull(TelemetryHelper::getEnvironmentProvider()); } @@ -63,7 +75,7 @@ public function testGetEnvironmentProviderWithoutAnyEnvSet(): void { * Test the getEnvironmentProvider method when Acquia environment is detected. */ public function testGetEnvironmentProviderWithAcquia(): void { - TestBase::setEnvVars(['AH_SITE_ENVIRONMENT' => 'test']); + TestBase::setEnvVars(['AH_SITE_ENVIRONMENT' => self::ENV_VAR_DEFAULT_VALUE]); // We need to make sure our mocked method is used. Depending on the implementation, // this could involve setting it statically or using dependency injection. From ab5ecca5b2e1f925082c421e3466af6287751fea Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Thu, 23 May 2024 11:39:45 -0400 Subject: [PATCH 07/16] Skip mutation testing for getProviders(). --- src/Helpers/TelemetryHelper.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Helpers/TelemetryHelper.php b/src/Helpers/TelemetryHelper.php index 2ee099a71..ac616db94 100644 --- a/src/Helpers/TelemetryHelper.php +++ b/src/Helpers/TelemetryHelper.php @@ -201,6 +201,9 @@ private function getDefaultUserData(): array { } /** + * @infection-ignore-all + * Skipping infection testing for this because, it most cases, we expect that when a row from this array is changed + * it won't affect the return value. * @return array * An array of providers and their associated environment variables. */ From 44fef586956261bfa8a175ed9ef6958d3eade222 Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Thu, 23 May 2024 11:46:45 -0400 Subject: [PATCH 08/16] Updating comments. --- tests/phpunit/src/Misc/TelemetryHelperTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/src/Misc/TelemetryHelperTest.php b/tests/phpunit/src/Misc/TelemetryHelperTest.php index b90ece96e..316bd40c6 100644 --- a/tests/phpunit/src/Misc/TelemetryHelperTest.php +++ b/tests/phpunit/src/Misc/TelemetryHelperTest.php @@ -75,11 +75,11 @@ public function testGetEnvironmentProviderWithoutAnyEnvSet(): void { * Test the getEnvironmentProvider method when Acquia environment is detected. */ public function testGetEnvironmentProviderWithAcquia(): void { + // We test this separately from testEnvironmentProvider() because AH_SITE_ENVIRONMENT isn't in + // TelemetryHelper::getProviders(). Instead, we rely on AcquiaDrupalEnvironmentDetector::getAhEnv() in + // getEnvironmentProvider() to indirectly tell us if AH_SITE_ENVIRONMENT is set. This allows + // AcquiaDrupalEnvironmentDetector to handle any changes to the logic of detecting Acquia environments. TestBase::setEnvVars(['AH_SITE_ENVIRONMENT' => self::ENV_VAR_DEFAULT_VALUE]); - - // We need to make sure our mocked method is used. Depending on the implementation, - // this could involve setting it statically or using dependency injection. - // Expect 'acquia' to be returned since Acquia environment is mocked to be present. $this->assertEquals('acquia', TelemetryHelper::getEnvironmentProvider()); } From 2b5ecb5e26c5ea963177ade4501696a4b19a4ce2 Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Thu, 23 May 2024 12:01:39 -0400 Subject: [PATCH 09/16] Change providers list. --- src/Helpers/TelemetryHelper.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Helpers/TelemetryHelper.php b/src/Helpers/TelemetryHelper.php index ac616db94..75d498cec 100644 --- a/src/Helpers/TelemetryHelper.php +++ b/src/Helpers/TelemetryHelper.php @@ -211,7 +211,10 @@ public static function getProviders(): array { // Define the environment variables associated with each provider. return [ 'bamboo' => ['BAMBOO_BUILDNUMBER'], - 'bitbucket' => ['BITBUCKET_BRANCH'], + 'beanstalk' => ['BEANSTALK_ENVIRONMENT'], + 'bitbucket' => ['BITBUCKET_BUILD_NUMBER'], + 'bitrise' => ['BITRISE_IO'], + 'buddy' => ['BUDDY_WORKSPACE_ID'], 'circleci' => ['CIRCLECI'], 'codebuild' => ['CODEBUILD_BUILD_ID'], 'drone' => ['DRONE'], @@ -219,7 +222,9 @@ public static function getProviders(): array { 'gitlab' => ['GITLAB_CI'], 'heroku' => ['HEROKU_TEST_RUN_ID'], 'jenkins' => ['JENKINS_URL'], - 'octopus' => ['OCTOPUS_DEPLOYMENT_ID'], + 'pantheon' => ['PANTHEON_ENVIRONMENT'], + 'pipelines' => ['PIPELINE_ENV'], + 'platformsh' => ['PLATFORM_ENVIRONMENT'], 'teamcity' => ['TEAMCITY_VERSION'], 'travis' => ['TRAVIS'], ]; From c2543a7b8b510212750d39290943b20bbd2626e2 Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Thu, 23 May 2024 12:06:35 -0400 Subject: [PATCH 10/16] More mutation fixes. --- .../phpunit/src/Misc/TelemetryHelperTest.php | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tests/phpunit/src/Misc/TelemetryHelperTest.php b/tests/phpunit/src/Misc/TelemetryHelperTest.php index 316bd40c6..bf2166d82 100644 --- a/tests/phpunit/src/Misc/TelemetryHelperTest.php +++ b/tests/phpunit/src/Misc/TelemetryHelperTest.php @@ -24,6 +24,17 @@ public function tearDown(): void { 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); + } + protected function createCommand(): CommandBase { return $this->injectCommand(ClearCacheCommand::class); } @@ -50,6 +61,9 @@ public function providerTestEnvironmentProvider(): array { */ public function testEnvironmentProvider(string $provider, array $envVars): void { TestBase::setEnvVars($envVars); + if ($provider !== 'github') { + $this->unsetGitHubEnvVars(); + } $this->assertEquals($provider, TelemetryHelper::getEnvironmentProvider()); } @@ -57,15 +71,7 @@ public function testEnvironmentProvider(string $provider, array $envVars): void * Test the getEnvironmentProvider method when no environment provider is detected. */ public function testGetEnvironmentProviderWithoutAnyEnvSet(): 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); + $this->unsetGitHubEnvVars(); // Expect null since no provider environment variables are set. $this->assertNull(TelemetryHelper::getEnvironmentProvider()); From 64017fb2c0a8e1fcb6cd1d1facb01c159c4fc8a2 Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Thu, 23 May 2024 12:09:04 -0400 Subject: [PATCH 11/16] Cleanup --- tests/phpunit/src/Misc/TelemetryHelperTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/phpunit/src/Misc/TelemetryHelperTest.php b/tests/phpunit/src/Misc/TelemetryHelperTest.php index bf2166d82..24707c98d 100644 --- a/tests/phpunit/src/Misc/TelemetryHelperTest.php +++ b/tests/phpunit/src/Misc/TelemetryHelperTest.php @@ -60,10 +60,8 @@ public function providerTestEnvironmentProvider(): array { * @dataProvider providerTestEnvironmentProvider() */ public function testEnvironmentProvider(string $provider, array $envVars): void { + $this->unsetGitHubEnvVars(); TestBase::setEnvVars($envVars); - if ($provider !== 'github') { - $this->unsetGitHubEnvVars(); - } $this->assertEquals($provider, TelemetryHelper::getEnvironmentProvider()); } From 07540a766d855edd5d6b1c727a2dd1baf9b62b2f Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Thu, 23 May 2024 12:42:26 -0400 Subject: [PATCH 12/16] Add ddev and lando. --- src/Helpers/TelemetryHelper.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Helpers/TelemetryHelper.php b/src/Helpers/TelemetryHelper.php index 75d498cec..f35131108 100644 --- a/src/Helpers/TelemetryHelper.php +++ b/src/Helpers/TelemetryHelper.php @@ -139,6 +139,7 @@ public static function getEnvironmentProvider(): ?string { $providers = self::getProviders(); // Check for an Acquia environment first as it uses a method call rather than getenv. + // Under the hood, this checks the AH_SITE_ENVIRONMENT environment variable. This is set by Cloud IDE and Lando. if (AcquiaDrupalEnvironmentDetector::getAhEnv()) { return 'acquia'; } @@ -217,11 +218,13 @@ public static function getProviders(): array { 'buddy' => ['BUDDY_WORKSPACE_ID'], 'circleci' => ['CIRCLECI'], 'codebuild' => ['CODEBUILD_BUILD_ID'], + 'ddev' => ['IS_DDEV_PROJECT'], 'drone' => ['DRONE'], 'github' => ['GITHUB_ACTIONS'], 'gitlab' => ['GITLAB_CI'], 'heroku' => ['HEROKU_TEST_RUN_ID'], 'jenkins' => ['JENKINS_URL'], + 'lando' => ['LANDO'], 'pantheon' => ['PANTHEON_ENVIRONMENT'], 'pipelines' => ['PIPELINE_ENV'], 'platformsh' => ['PLATFORM_ENVIRONMENT'], From d8d08ec766c10381a8c1896530c0edc16b7edcfa Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Thu, 23 May 2024 15:00:50 -0400 Subject: [PATCH 13/16] Change to TestBase. --- src/Helpers/TelemetryHelper.php | 2 ++ tests/phpunit/src/Misc/TelemetryHelperTest.php | 7 +------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Helpers/TelemetryHelper.php b/src/Helpers/TelemetryHelper.php index f35131108..afdb9cddc 100644 --- a/src/Helpers/TelemetryHelper.php +++ b/src/Helpers/TelemetryHelper.php @@ -230,6 +230,8 @@ public static function getProviders(): array { 'platformsh' => ['PLATFORM_ENVIRONMENT'], 'teamcity' => ['TEAMCITY_VERSION'], 'travis' => ['TRAVIS'], + // docksal? + // docker? ]; } diff --git a/tests/phpunit/src/Misc/TelemetryHelperTest.php b/tests/phpunit/src/Misc/TelemetryHelperTest.php index 24707c98d..d3912d5ab 100644 --- a/tests/phpunit/src/Misc/TelemetryHelperTest.php +++ b/tests/phpunit/src/Misc/TelemetryHelperTest.php @@ -7,10 +7,9 @@ use Acquia\Cli\Command\CommandBase; use Acquia\Cli\Command\Self\ClearCacheCommand; use Acquia\Cli\Helpers\TelemetryHelper; -use Acquia\Cli\Tests\CommandTestBase; use Acquia\Cli\Tests\TestBase; -class TelemetryHelperTest extends CommandTestBase { +class TelemetryHelperTest extends TestBase { const ENV_VAR_DEFAULT_VALUE = 'test'; @@ -35,10 +34,6 @@ public function unsetGitHubEnvVars(): void { TestBase::unsetEnvVars($github_env_vars); } - protected function createCommand(): CommandBase { - return $this->injectCommand(ClearCacheCommand::class); - } - /** * @return array */ From 5a2d68509a3f6b1689ca2bce2fb3afa38e291d66 Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Thu, 23 May 2024 13:10:27 -0700 Subject: [PATCH 14/16] Remove unused includes --- tests/phpunit/src/Misc/TelemetryHelperTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/phpunit/src/Misc/TelemetryHelperTest.php b/tests/phpunit/src/Misc/TelemetryHelperTest.php index d3912d5ab..067bcaff5 100644 --- a/tests/phpunit/src/Misc/TelemetryHelperTest.php +++ b/tests/phpunit/src/Misc/TelemetryHelperTest.php @@ -4,8 +4,6 @@ namespace Acquia\Cli\Tests\Misc; -use Acquia\Cli\Command\CommandBase; -use Acquia\Cli\Command\Self\ClearCacheCommand; use Acquia\Cli\Helpers\TelemetryHelper; use Acquia\Cli\Tests\TestBase; From 0fbbf4a0fb9cb1e9b44f81f337f08e3148ef5873 Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Thu, 23 May 2024 16:18:42 -0400 Subject: [PATCH 15/16] Fix lando and ddev hijacking. --- src/Helpers/TelemetryHelper.php | 16 ++++++---------- tests/phpunit/src/Misc/TelemetryHelperTest.php | 16 +--------------- 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/src/Helpers/TelemetryHelper.php b/src/Helpers/TelemetryHelper.php index afdb9cddc..27b0981db 100644 --- a/src/Helpers/TelemetryHelper.php +++ b/src/Helpers/TelemetryHelper.php @@ -138,12 +138,6 @@ private function getTelemetryUserData(): array { public static function getEnvironmentProvider(): ?string { $providers = self::getProviders(); - // Check for an Acquia environment first as it uses a method call rather than getenv. - // Under the hood, this checks the AH_SITE_ENVIRONMENT environment variable. This is set by Cloud IDE and Lando. - if (AcquiaDrupalEnvironmentDetector::getAhEnv()) { - return 'acquia'; - } - // Check for environment variables. foreach ($providers as $provider => $vars) { foreach ($vars as $var) { @@ -205,12 +199,17 @@ private function getDefaultUserData(): array { * @infection-ignore-all * Skipping infection testing for this because, it most cases, we expect that when a row from this array is changed * it won't affect the return value. + * * @return array * An array of providers and their associated environment variables. */ public static function getProviders(): array { // Define the environment variables associated with each provider. return [ + 'lando' => ['LANDO'], + 'ddev' => ['IS_DDEV_PROJECT'], + // Check Lando and DDEV first because the hijack AH_SITE_ENVIRONMENT. + 'acquia' => ['AH_SITE_ENVIRONMENT'], 'bamboo' => ['BAMBOO_BUILDNUMBER'], 'beanstalk' => ['BEANSTALK_ENVIRONMENT'], 'bitbucket' => ['BITBUCKET_BUILD_NUMBER'], @@ -218,20 +217,17 @@ public static function getProviders(): array { 'buddy' => ['BUDDY_WORKSPACE_ID'], 'circleci' => ['CIRCLECI'], 'codebuild' => ['CODEBUILD_BUILD_ID'], - 'ddev' => ['IS_DDEV_PROJECT'], + 'docksal' => ['DOCKSAL_VERSION'], 'drone' => ['DRONE'], 'github' => ['GITHUB_ACTIONS'], 'gitlab' => ['GITLAB_CI'], 'heroku' => ['HEROKU_TEST_RUN_ID'], 'jenkins' => ['JENKINS_URL'], - 'lando' => ['LANDO'], 'pantheon' => ['PANTHEON_ENVIRONMENT'], 'pipelines' => ['PIPELINE_ENV'], 'platformsh' => ['PLATFORM_ENVIRONMENT'], 'teamcity' => ['TEAMCITY_VERSION'], 'travis' => ['TRAVIS'], - // docksal? - // docker? ]; } diff --git a/tests/phpunit/src/Misc/TelemetryHelperTest.php b/tests/phpunit/src/Misc/TelemetryHelperTest.php index d3912d5ab..c4baa34fe 100644 --- a/tests/phpunit/src/Misc/TelemetryHelperTest.php +++ b/tests/phpunit/src/Misc/TelemetryHelperTest.php @@ -4,8 +4,6 @@ namespace Acquia\Cli\Tests\Misc; -use Acquia\Cli\Command\CommandBase; -use Acquia\Cli\Command\Self\ClearCacheCommand; use Acquia\Cli\Helpers\TelemetryHelper; use Acquia\Cli\Tests\TestBase; @@ -15,7 +13,7 @@ class TelemetryHelperTest extends TestBase { public function tearDown(): void { parent::tearDown(); - $envVars = ['AH_SITE_ENVIRONMENT' => 'test']; + $envVars = []; foreach ($this->providerTestEnvironmentProvider() as $args) { $envVars = array_merge($envVars, $args[1]); } @@ -70,16 +68,4 @@ public function testGetEnvironmentProviderWithoutAnyEnvSet(): void { $this->assertNull(TelemetryHelper::getEnvironmentProvider()); } - /** - * Test the getEnvironmentProvider method when Acquia environment is detected. - */ - public function testGetEnvironmentProviderWithAcquia(): void { - // We test this separately from testEnvironmentProvider() because AH_SITE_ENVIRONMENT isn't in - // TelemetryHelper::getProviders(). Instead, we rely on AcquiaDrupalEnvironmentDetector::getAhEnv() in - // getEnvironmentProvider() to indirectly tell us if AH_SITE_ENVIRONMENT is set. This allows - // AcquiaDrupalEnvironmentDetector to handle any changes to the logic of detecting Acquia environments. - TestBase::setEnvVars(['AH_SITE_ENVIRONMENT' => self::ENV_VAR_DEFAULT_VALUE]); - $this->assertEquals('acquia', TelemetryHelper::getEnvironmentProvider()); - } - } From 33e55c8d86b87a6c5b3de97be242d86a382daffb Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Thu, 23 May 2024 16:24:31 -0400 Subject: [PATCH 16/16] PHPCS ignore. --- src/Helpers/TelemetryHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Helpers/TelemetryHelper.php b/src/Helpers/TelemetryHelper.php index 27b0981db..7fd8b44ae 100644 --- a/src/Helpers/TelemetryHelper.php +++ b/src/Helpers/TelemetryHelper.php @@ -199,12 +199,12 @@ private function getDefaultUserData(): array { * @infection-ignore-all * Skipping infection testing for this because, it most cases, we expect that when a row from this array is changed * it won't affect the return value. - * * @return array * An array of providers and their associated environment variables. */ public static function getProviders(): array { // Define the environment variables associated with each provider. + // phpcs:ignore SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder return [ 'lando' => ['LANDO'], 'ddev' => ['IS_DDEV_PROJECT'],