From 593c4651653fbd3731e243610677d9e45f2070e3 Mon Sep 17 00:00:00 2001 From: Dave Reid Date: Tue, 27 Jun 2023 09:06:16 -0500 Subject: [PATCH 01/20] Move environments into a Environment/ subdirectory. --- src/Environment.php | 12 ++++++------ .../Acquia.php} | 4 ++-- .../CircleCi.php} | 4 ++-- src/{ => Environment}/DefaultEnvironment.php | 2 +- .../GitHubWorkflow.php} | 4 ++-- .../GitLabCi.php} | 4 ++-- .../Pantheon.php} | 5 +++-- 7 files changed, 18 insertions(+), 17 deletions(-) rename src/{AcquiaEnvironment.php => Environment/Acquia.php} (83%) rename src/{CircleCiEnvironment.php => Environment/CircleCi.php} (77%) rename src/{ => Environment}/DefaultEnvironment.php (98%) rename src/{GitHubWorkflowEnvironment.php => Environment/GitHubWorkflow.php} (78%) rename src/{GitLabCiEnvironment.php => Environment/GitLabCi.php} (79%) rename src/{PantheonEnvironment.php => Environment/Pantheon.php} (91%) diff --git a/src/Environment.php b/src/Environment.php index a4c4a7d..453ad35 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -27,12 +27,12 @@ class Environment * The currently supported environment classes. */ public const CLASSES = [ - 'isAcquia' => AcquiaEnvironment::class, - 'isPantheon' => PantheonEnvironment::class, - 'isGitHubWorkflow' => GitHubWorkflowEnvironment::class, - 'isGitLabCi' => GitLabCiEnvironment::class, - 'isCircleCi' => CircleCiEnvironment::class, - null => DefaultEnvironment::class, + 'isAcquia' => \Davereid\DrupalEnvironment\Environment\Acquia::class, + 'isPantheon' => \Davereid\DrupalEnvironment\Environment\Pantheon::class, + 'isGitHubWorkflow' => \Davereid\DrupalEnvironment\Environment\GitHubWorkflow::class, + 'isGitLabCi' => \Davereid\DrupalEnvironment\Environment\GitLabCi::class, + 'isCircleCi' => \Davereid\DrupalEnvironment\Environment\CircleCi::class, + null => \Davereid\DrupalEnvironment\Environment\DefaultEnvironment::class, ]; /** diff --git a/src/AcquiaEnvironment.php b/src/Environment/Acquia.php similarity index 83% rename from src/AcquiaEnvironment.php rename to src/Environment/Acquia.php index 248dee0..e34a6e2 100644 --- a/src/AcquiaEnvironment.php +++ b/src/Environment/Acquia.php @@ -1,6 +1,6 @@ Date: Tue, 27 Jun 2023 09:09:09 -0500 Subject: [PATCH 02/20] Move get method to DefaultEnvironment. --- src/Environment.php | 23 ++--------------------- src/Environment/DefaultEnvironment.php | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/Environment.php b/src/Environment.php index 453ad35..1fdd6fc 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -5,8 +5,7 @@ /** * Helpers for working with the Drupal environment. * - * @todo Add Platform.sh support - * + * @method static mixed get(string $name) * @method static string getEnvironment() * @method static bool isAcquia() * @method static bool isPantheon() @@ -52,7 +51,7 @@ public static function getEnvironmentClass() // Intentionally re-assigning the class variable here so that a match // breaks the foreach loop, or we fall back to the default class. foreach (static::CLASSES as $class) { - if (static::get($class::ENVIRONMENT_NAME)) { + if (getenv($class::ENVIRONMENT_NAME)) { break; } } @@ -76,24 +75,6 @@ public static function __callStatic(string $name, array $arguments) return $class::$name(...$arguments); } - /** - * Get an environment variable. - * - * @param string $name - * The name of the environment variable to retrieve. - * - * @return mixed - * The environment variable, if it's set. - */ - public static function get(string $name) - { - static $cache = []; - if (!array_key_exists($name, $cache)) { - $cache[$name] = getenv($name); - } - return $cache[$name]; - } - /** * Determine if this is a local environment. * diff --git a/src/Environment/DefaultEnvironment.php b/src/Environment/DefaultEnvironment.php index 307b240..0406e55 100644 --- a/src/Environment/DefaultEnvironment.php +++ b/src/Environment/DefaultEnvironment.php @@ -43,6 +43,24 @@ class DefaultEnvironment */ public const CI = 'ci'; + /** + * Get an environment variable. + * + * @param string $name + * The name of the environment variable to retrieve. + * + * @return mixed + * The environment variable, if it's set. + */ + public static function get(string $name) + { + static $cache = []; + if (!array_key_exists($name, $cache)) { + $cache[$name] = getenv($name); + } + return $cache[$name]; + } + /** * Return the environment name. * From 2cad050e7c637cf499521e462cfb3b9d713ac36c Mon Sep 17 00:00:00 2001 From: Dave Reid Date: Tue, 27 Jun 2023 09:10:56 -0500 Subject: [PATCH 03/20] Fix another call to getenv(). --- src/Environment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Environment.php b/src/Environment.php index 1fdd6fc..8715bea 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -44,7 +44,7 @@ public static function getEnvironmentClass() { static $class; if (!isset($class)) { - if ($class = static::get('DRUPAL_ENVIRONMENT_CLASS')) { + if ($class = getenv('DRUPAL_ENVIRONMENT_CLASS')) { // Do nothing. The class was assigned in the if. } else { From 793c3db2c3a2b362b98fb036080003e6a36a51d6 Mon Sep 17 00:00:00 2001 From: Dave Reid Date: Tue, 27 Jun 2023 09:14:14 -0500 Subject: [PATCH 04/20] Use imports and ::class. --- src/Environment.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Environment.php b/src/Environment.php index 8715bea..61c238b 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -2,6 +2,13 @@ namespace Davereid\DrupalEnvironment; +use Davereid\DrupalEnvironment\Environment\Acquia; +use Davereid\DrupalEnvironment\Environment\CircleCi; +use Davereid\DrupalEnvironment\Environment\DefaultEnvironment; +use Davereid\DrupalEnvironment\Environment\GitHubWorkflow; +use Davereid\DrupalEnvironment\Environment\GitLabCi; +use Davereid\DrupalEnvironment\Environment\Pantheon; + /** * Helpers for working with the Drupal environment. * @@ -26,12 +33,12 @@ class Environment * The currently supported environment classes. */ public const CLASSES = [ - 'isAcquia' => \Davereid\DrupalEnvironment\Environment\Acquia::class, - 'isPantheon' => \Davereid\DrupalEnvironment\Environment\Pantheon::class, - 'isGitHubWorkflow' => \Davereid\DrupalEnvironment\Environment\GitHubWorkflow::class, - 'isGitLabCi' => \Davereid\DrupalEnvironment\Environment\GitLabCi::class, - 'isCircleCi' => \Davereid\DrupalEnvironment\Environment\CircleCi::class, - null => \Davereid\DrupalEnvironment\Environment\DefaultEnvironment::class, + 'isAcquia' => Acquia::class, + 'isPantheon' => Pantheon::class, + 'isGitHubWorkflow' => GitHubWorkflow::class, + 'isGitLabCi' => GitLabCi::class, + 'isCircleCi' => CircleCi::class, + null => DefaultEnvironment::class, ]; /** From 4d8590e5ba8824b768fb9814408d8f7a599bbce4 Mon Sep 17 00:00:00 2001 From: Dave Reid Date: Tue, 27 Jun 2023 09:18:30 -0500 Subject: [PATCH 05/20] Added phpcodesniffer and phpmd codeclimate plugins. --- .codeclimate.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.codeclimate.yml b/.codeclimate.yml index df102ca..969ad6c 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -1,2 +1,7 @@ +plugins: + phpcodesniffer: + enabled: true + phpmd: + enabled: true exclude_patterns: - "tests/" From 9bfd50ceaa771c5aa9aaaabd6c6e630a1ba0802d Mon Sep 17 00:00:00 2001 From: Dave Reid Date: Tue, 27 Jun 2023 09:37:41 -0500 Subject: [PATCH 06/20] Moved Tugboat to separate environment. --- src/Environment.php | 15 ++------------- src/Environment/DefaultEnvironment.php | 26 +++++++++++++++++++++++--- src/Environment/Pantheon.php | 3 +-- src/Environment/Tugboat.php | 26 ++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 18 deletions(-) create mode 100644 src/Environment/Tugboat.php diff --git a/src/Environment.php b/src/Environment.php index 61c238b..abc14a1 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -8,6 +8,7 @@ use Davereid\DrupalEnvironment\Environment\GitHubWorkflow; use Davereid\DrupalEnvironment\Environment\GitLabCi; use Davereid\DrupalEnvironment\Environment\Pantheon; +use Davereid\DrupalEnvironment\Environment\Tugboat; /** * Helpers for working with the Drupal environment. @@ -35,6 +36,7 @@ class Environment public const CLASSES = [ 'isAcquia' => Acquia::class, 'isPantheon' => Pantheon::class, + 'isTugboat' => Tugboat::class, 'isGitHubWorkflow' => GitHubWorkflow::class, 'isGitLabCi' => GitLabCi::class, 'isCircleCi' => CircleCi::class, @@ -119,19 +121,6 @@ public static function isLando(): bool return (bool)static::get('LANDO_INFO'); } - /** - * Determine if this is a Tugboat environment. - * - * @return bool - * TRUE if this is a Tugboat environment. - * - * @todo Should this be its own environment class? - */ - public static function isTugboat(): bool - { - return static::getEnvironment() === 'tugboat'; - } - /** * Determines whether the current request is a command-line one. * diff --git a/src/Environment/DefaultEnvironment.php b/src/Environment/DefaultEnvironment.php index 0406e55..d8d8fee 100644 --- a/src/Environment/DefaultEnvironment.php +++ b/src/Environment/DefaultEnvironment.php @@ -2,6 +2,8 @@ namespace Davereid\DrupalEnvironment\Environment; +use Davereid\DrupalEnvironment\Environment; + /** * The standard environment. */ @@ -36,6 +38,13 @@ class DefaultEnvironment */ public const DEVELOPMENT = 'dev'; + /** + * The default preview environment name. + * + * @var string + */ + public const PREVIEW = 'preview'; + /** * The default CI environment name. * @@ -71,7 +80,7 @@ public static function get(string $name) */ public static function getEnvironment(): string { - return Environment::get(static::ENVIRONMENT_NAME); + return static::get(static::ENVIRONMENT_NAME); } /** @@ -115,7 +124,7 @@ public static function isDevelopment(): bool */ public static function isPreview(): bool { - return Environment::isTugboat(); + return static::getEnvironment() === static::PREVIEW; } /** @@ -129,6 +138,17 @@ public static function isCi(): bool return static::getEnvironment() === static::CI; } + /** + * Determine if this is a local environment. + * + * @return bool + * TRUE if this is local. + */ + public static function isLocal(): bool + { + return Environment::isLocal(); + } + /** * Get the environment_indicator configuration. for this environment. * @@ -166,7 +186,7 @@ public static function getIndicatorConfig(): ?array { 'fg_color' => '#990055', ]; } - if (Environment::isLocal()) { + if (static::isLocal()) { return [ 'name' => 'Local', 'bg_color' => '#ffffff', diff --git a/src/Environment/Pantheon.php b/src/Environment/Pantheon.php index 7c35da3..d19853b 100644 --- a/src/Environment/Pantheon.php +++ b/src/Environment/Pantheon.php @@ -2,7 +2,6 @@ namespace Davereid\DrupalEnvironment\Environment; - /** * The Pantheon environment specifics. * @@ -44,7 +43,7 @@ public static function isMultidev(): bool && !static::isStaging() && !static::isDevelopment() && !static::isCi() - && !Environment::isLocal(); + && !static::isLocal(); } } diff --git a/src/Environment/Tugboat.php b/src/Environment/Tugboat.php new file mode 100644 index 0000000..4dc2435 --- /dev/null +++ b/src/Environment/Tugboat.php @@ -0,0 +1,26 @@ + Date: Tue, 27 Jun 2023 09:40:54 -0500 Subject: [PATCH 07/20] Fixing coding standards. --- src/Environment.php | 3 +-- src/Environment/Acquia.php | 1 - src/Environment/CircleCi.php | 1 - src/Environment/DefaultEnvironment.php | 5 +++-- src/Environment/Tugboat.php | 2 +- 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Environment.php b/src/Environment.php index abc14a1..d23bc6f 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -55,8 +55,7 @@ public static function getEnvironmentClass() if (!isset($class)) { if ($class = getenv('DRUPAL_ENVIRONMENT_CLASS')) { // Do nothing. The class was assigned in the if. - } - else { + } else { // Intentionally re-assigning the class variable here so that a match // breaks the foreach loop, or we fall back to the default class. foreach (static::CLASSES as $class) { diff --git a/src/Environment/Acquia.php b/src/Environment/Acquia.php index e34a6e2..25e3e1c 100644 --- a/src/Environment/Acquia.php +++ b/src/Environment/Acquia.php @@ -19,5 +19,4 @@ class Acquia extends DefaultEnvironment * {@inheritdoc} */ public const ENVIRONMENT_NAME = 'AH_SITE_ENVIRONMENT'; - } diff --git a/src/Environment/CircleCi.php b/src/Environment/CircleCi.php index 835ed16..d4602bd 100644 --- a/src/Environment/CircleCi.php +++ b/src/Environment/CircleCi.php @@ -22,5 +22,4 @@ public static function getEnvironment(): string { return static::CI; } - } diff --git a/src/Environment/DefaultEnvironment.php b/src/Environment/DefaultEnvironment.php index d8d8fee..1302dfe 100644 --- a/src/Environment/DefaultEnvironment.php +++ b/src/Environment/DefaultEnvironment.php @@ -157,7 +157,8 @@ public static function isLocal(): bool * * @see https://architecture.lullabot.com/adr/20210609-environment-indicator/ */ - public static function getIndicatorConfig(): ?array { + public static function getIndicatorConfig(): ?array + { if (static::isProduction()) { return [ 'name' => 'Production', @@ -195,7 +196,7 @@ public static function getIndicatorConfig(): ?array { } // Unknown environment condition. - return NULL; + return null; } } diff --git a/src/Environment/Tugboat.php b/src/Environment/Tugboat.php index 4dc2435..7769760 100644 --- a/src/Environment/Tugboat.php +++ b/src/Environment/Tugboat.php @@ -20,7 +20,7 @@ class Tugboat extends DefaultEnvironment */ public static function isPreview(): bool { - return TRUE; + return true; } } From 2427f72e1fd282ceca87ca42e4ac201ffe196ebd Mon Sep 17 00:00:00 2001 From: Dave Reid Date: Tue, 27 Jun 2023 09:44:19 -0500 Subject: [PATCH 08/20] Fixing more coding standards. --- composer.json | 3 +- tests/src/EnvironmentTest.php | 356 +++++++++++++++++----------------- 2 files changed, 182 insertions(+), 177 deletions(-) diff --git a/composer.json b/composer.json index bf5a8df..f812862 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,8 @@ "phpstan/extension-installer": "^1.3", "phpstan/phpstan-deprecation-rules": "^1.1", "roave/security-advisories": "dev-master", - "symfony/phpunit-bridge": "^6.3" + "symfony/phpunit-bridge": "^6.3", + "squizlabs/php_codesniffer": "^3.7" }, "autoload": { "psr-4": { diff --git a/tests/src/EnvironmentTest.php b/tests/src/EnvironmentTest.php index 2cfa8c1..856a635 100644 --- a/tests/src/EnvironmentTest.php +++ b/tests/src/EnvironmentTest.php @@ -16,7 +16,8 @@ final class EnvironmentTest extends TestCase * * @covers \Davereid\DrupalEnvironment\Environment::commandExists */ - public function testCommandExists(): void { + public function testCommandExists(): void + { $this->assertTrue(Environment::commandExists('php')); $this->assertFalse(Environment::commandExists('invalid-command')); } @@ -26,14 +27,15 @@ public function testCommandExists(): void { * * @dataProvider providerEnvironment */ - public function testEnvironment(array $variables, array $method_tests): void { + public function testEnvironment(array $variables, array $method_tests): void + { $variables += [ - 'ENVIRONMENT' => NULL, - 'PANTHEON_ENVIRONMENT' => NULL, + 'ENVIRONMENT' => null, + 'PANTHEON_ENVIRONMENT' => null, // When running under CI, we need to ensure these are reset. - 'CI' => NULL, - 'GITLAB_CI' => NULL, - 'GITHUB_WORKFLOW' => NULL, + 'CI' => null, + 'GITLAB_CI' => null, + 'GITHUB_WORKFLOW' => null, ]; $originals = []; $this->setEnvironmentVariables($variables, $originals); @@ -47,7 +49,8 @@ public function testEnvironment(array $variables, array $method_tests): void { * @param array $variables * @param array|null $originals */ - protected function setEnvironmentVariables(array $variables, ?array &$originals = NULL): void { + protected function setEnvironmentVariables(array $variables, ?array &$originals = null): void + { foreach ($variables as $name => $value) { if (isset($originals)) { $originals[$name] = getenv($name) ?: null; @@ -59,25 +62,26 @@ protected function setEnvironmentVariables(array $variables, ?array &$originals /** * Data provider for ::testEnvironment. */ - public function providerEnvironment(): array { + public function providerEnvironment(): array + { return [ 'default-state' => [ [], [ 'getEnvironment' => '', - 'isAcquia' => FALSE, - 'isCircleCi' => FALSE, - 'isGitHubWorkflow' => FALSE, - 'isGitLabCi' => FALSE, - 'isPantheon' => FALSE, - 'isProduction' => FALSE, - 'isStaging' => FALSE, - 'isDevelopment' => FALSE, - 'isPreview' => FALSE, - 'isCi' => FALSE, + 'isAcquia' => false, + 'isCircleCi' => false, + 'isGitHubWorkflow' => false, + 'isGitLabCi' => false, + 'isPantheon' => false, + 'isProduction' => false, + 'isStaging' => false, + 'isDevelopment' => false, + 'isPreview' => false, + 'isCi' => false, 'isCli' => (PHP_SAPI === 'cli'), - 'isLocal' => FALSE, - 'getIndicatorConfig' => NULL, + 'isLocal' => false, + 'getIndicatorConfig' => null, 'getComposerFilename' => 'composer.json', 'getComposerLockFilename' => 'composer.lock', ], @@ -88,17 +92,17 @@ public function providerEnvironment(): array { ], [ 'getEnvironment' => 'prod', - 'isAcquia' => FALSE, - 'isCircleCi' => FALSE, - 'isGitHubWorkflow' => FALSE, - 'isGitLabCi' => FALSE, - 'isPantheon' => FALSE, - 'isProduction' => TRUE, - 'isStaging' => FALSE, - 'isDevelopment' => FALSE, - 'isPreview' => FALSE, - 'isCi' => FALSE, - 'isLocal' => FALSE, + 'isAcquia' => false, + 'isCircleCi' => false, + 'isGitHubWorkflow' => false, + 'isGitLabCi' => false, + 'isPantheon' => false, + 'isProduction' => true, + 'isStaging' => false, + 'isDevelopment' => false, + 'isPreview' => false, + 'isCi' => false, + 'isLocal' => false, 'getIndicatorConfig' => [ 'name' => 'Production', 'bg_color' => '#ffffff', @@ -112,18 +116,18 @@ public function providerEnvironment(): array { ], [ 'getEnvironment' => '', - 'isAcquia' => FALSE, - 'isCircleCi' => FALSE, - 'isGitHubWorkflow' => FALSE, - 'isGitLabCi' => FALSE, - 'isPantheon' => FALSE, - 'isProduction' => FALSE, - 'isStaging' => FALSE, - 'isDevelopment' => FALSE, - 'isPreview' => FALSE, - 'isCi' => FALSE, - 'isLocal' => FALSE, - 'getIndicatorConfig' => NULL, + 'isAcquia' => false, + 'isCircleCi' => false, + 'isGitHubWorkflow' => false, + 'isGitLabCi' => false, + 'isPantheon' => false, + 'isProduction' => false, + 'isStaging' => false, + 'isDevelopment' => false, + 'isPreview' => false, + 'isCi' => false, + 'isLocal' => false, + 'getIndicatorConfig' => null, ], ], 'pantheon-live' => [ @@ -132,18 +136,18 @@ public function providerEnvironment(): array { ], [ 'getEnvironment' => 'live', - 'isAcquia' => FALSE, - 'isCircleCi' => FALSE, - 'isGitHubWorkflow' => FALSE, - 'isGitLabCi' => FALSE, - 'isPantheon' => TRUE, - 'isProduction' => TRUE, - 'isStaging' => FALSE, - 'isDevelopment' => FALSE, - 'isPreview' => FALSE, - 'isMultidev' => FALSE, - 'isCi' => FALSE, - 'isLocal' => FALSE, + 'isAcquia' => false, + 'isCircleCi' => false, + 'isGitHubWorkflow' => false, + 'isGitLabCi' => false, + 'isPantheon' => true, + 'isProduction' => true, + 'isStaging' => false, + 'isDevelopment' => false, + 'isPreview' => false, + 'isMultidev' => false, + 'isCi' => false, + 'isLocal' => false, 'getIndicatorConfig' => [ 'name' => 'Production', 'bg_color' => '#ffffff', @@ -157,18 +161,18 @@ public function providerEnvironment(): array { ], [ 'getEnvironment' => 'test', - 'isAcquia' => FALSE, - 'isCircleCi' => FALSE, - 'isGitHubWorkflow' => FALSE, - 'isGitLabCi' => FALSE, - 'isPantheon' => TRUE, - 'isProduction' => FALSE, - 'isStaging' => TRUE, - 'isDevelopment' => FALSE, - 'isPreview' => FALSE, - 'isMultidev' => FALSE, - 'isCi' => FALSE, - 'isLocal' => FALSE, + 'isAcquia' => false, + 'isCircleCi' => false, + 'isGitHubWorkflow' => false, + 'isGitLabCi' => false, + 'isPantheon' => true, + 'isProduction' => false, + 'isStaging' => true, + 'isDevelopment' => false, + 'isPreview' => false, + 'isMultidev' => false, + 'isCi' => false, + 'isLocal' => false, 'getIndicatorConfig' => [ 'name' => 'Staging', 'bg_color' => '#ffffff', @@ -182,18 +186,18 @@ public function providerEnvironment(): array { ], [ 'getEnvironment' => 'dev', - 'isAcquia' => FALSE, - 'isCircleCi' => FALSE, - 'isGitHubWorkflow' => FALSE, - 'isGitLabCi' => FALSE, - 'isPantheon' => TRUE, - 'isProduction' => FALSE, - 'isStaging' => FALSE, - 'isDevelopment' => TRUE, - 'isPreview' => FALSE, - 'isMultidev' => FALSE, - 'isCi' => FALSE, - 'isLocal' => FALSE, + 'isAcquia' => false, + 'isCircleCi' => false, + 'isGitHubWorkflow' => false, + 'isGitLabCi' => false, + 'isPantheon' => true, + 'isProduction' => false, + 'isStaging' => false, + 'isDevelopment' => true, + 'isPreview' => false, + 'isMultidev' => false, + 'isCi' => false, + 'isLocal' => false, 'getIndicatorConfig' => [ 'name' => 'Development', 'bg_color' => '#ffffff', @@ -207,18 +211,18 @@ public function providerEnvironment(): array { ], [ 'getEnvironment' => 'pr-1', - 'isAcquia' => FALSE, - 'isCircleCi' => FALSE, - 'isGitHubWorkflow' => FALSE, - 'isGitLabCi' => FALSE, - 'isPantheon' => TRUE, - 'isProduction' => FALSE, - 'isStaging' => FALSE, - 'isDevelopment' => FALSE, - 'isPreview' => TRUE, - 'isMultidev' => TRUE, - 'isCi' => FALSE, - 'isLocal' => FALSE, + 'isAcquia' => false, + 'isCircleCi' => false, + 'isGitHubWorkflow' => false, + 'isGitLabCi' => false, + 'isPantheon' => true, + 'isProduction' => false, + 'isStaging' => false, + 'isDevelopment' => false, + 'isPreview' => true, + 'isMultidev' => true, + 'isCi' => false, + 'isLocal' => false, 'getIndicatorConfig' => [ 'name' => 'Preview', 'bg_color' => '#ffffff', @@ -232,19 +236,19 @@ public function providerEnvironment(): array { ], [ 'getEnvironment' => 'ci', - 'isAcquia' => FALSE, - 'isCircleCi' => FALSE, - 'isGitHubWorkflow' => FALSE, - 'isGitLabCi' => FALSE, - 'isPantheon' => TRUE, - 'isProduction' => FALSE, - 'isStaging' => FALSE, - 'isDevelopment' => FALSE, - 'isPreview' => FALSE, - 'isMultidev' => FALSE, - 'isCi' => TRUE, - 'isLocal' => FALSE, - 'getIndicatorConfig' => NULL, + 'isAcquia' => false, + 'isCircleCi' => false, + 'isGitHubWorkflow' => false, + 'isGitLabCi' => false, + 'isPantheon' => true, + 'isProduction' => false, + 'isStaging' => false, + 'isDevelopment' => false, + 'isPreview' => false, + 'isMultidev' => false, + 'isCi' => true, + 'isLocal' => false, + 'getIndicatorConfig' => null, ], ], 'pantheon-local' => [ @@ -253,18 +257,18 @@ public function providerEnvironment(): array { ], [ 'getEnvironment' => 'local', - 'isAcquia' => FALSE, - 'isCircleCi' => FALSE, - 'isGitHubWorkflow' => FALSE, - 'isGitLabCi' => FALSE, - 'isPantheon' => TRUE, - 'isProduction' => FALSE, - 'isStaging' => FALSE, - 'isDevelopment' => FALSE, - 'isPreview' => FALSE, - 'isMultidev' => FALSE, - 'isCi' => FALSE, - 'isLocal' => TRUE, + 'isAcquia' => false, + 'isCircleCi' => false, + 'isGitHubWorkflow' => false, + 'isGitLabCi' => false, + 'isPantheon' => true, + 'isProduction' => false, + 'isStaging' => false, + 'isDevelopment' => false, + 'isPreview' => false, + 'isMultidev' => false, + 'isCi' => false, + 'isLocal' => true, 'getIndicatorConfig' => [ 'name' => 'Local', 'bg_color' => '#ffffff', @@ -279,18 +283,18 @@ public function providerEnvironment(): array { ], [ 'getEnvironment' => 'ci', - 'isAcquia' => FALSE, - 'isCircleCi' => TRUE, - 'isGitHubWorkflow' => FALSE, - 'isGitLabCi' => FALSE, - 'isPantheon' => FALSE, - 'isProduction' => FALSE, - 'isStaging' => FALSE, - 'isDevelopment' => FALSE, - 'isPreview' => FALSE, - 'isCi' => TRUE, - 'isLocal' => FALSE, - 'getIndicatorConfig' => NULL, + 'isAcquia' => false, + 'isCircleCi' => true, + 'isGitHubWorkflow' => false, + 'isGitLabCi' => false, + 'isPantheon' => false, + 'isProduction' => false, + 'isStaging' => false, + 'isDevelopment' => false, + 'isPreview' => false, + 'isCi' => true, + 'isLocal' => false, + 'getIndicatorConfig' => null, ], ], 'github' => [ @@ -300,18 +304,18 @@ public function providerEnvironment(): array { ], [ 'getEnvironment' => 'ci', - 'isAcquia' => FALSE, - 'isCircleCi' => FALSE, - 'isGitHubWorkflow' => TRUE, - 'isGitLabCi' => FALSE, - 'isPantheon' => FALSE, - 'isProduction' => FALSE, - 'isStaging' => FALSE, - 'isDevelopment' => FALSE, - 'isPreview' => FALSE, - 'isCi' => TRUE, - 'isLocal' => FALSE, - 'getIndicatorConfig' => NULL, + 'isAcquia' => false, + 'isCircleCi' => false, + 'isGitHubWorkflow' => true, + 'isGitLabCi' => false, + 'isPantheon' => false, + 'isProduction' => false, + 'isStaging' => false, + 'isDevelopment' => false, + 'isPreview' => false, + 'isCi' => true, + 'isLocal' => false, + 'getIndicatorConfig' => null, ], ], 'gitlab' => [ @@ -321,37 +325,37 @@ public function providerEnvironment(): array { ], [ 'getEnvironment' => 'ci', - 'isAcquia' => FALSE, - 'isCircleCi' => FALSE, - 'isGitHubWorkflow' => FALSE, - 'isGitLabCi' => TRUE, - 'isPantheon' => FALSE, - 'isProduction' => FALSE, - 'isStaging' => FALSE, - 'isDevelopment' => FALSE, - 'isPreview' => FALSE, - 'isCi' => TRUE, - 'isLocal' => FALSE, - 'getIndicatorConfig' => NULL, + 'isAcquia' => false, + 'isCircleCi' => false, + 'isGitHubWorkflow' => false, + 'isGitLabCi' => true, + 'isPantheon' => false, + 'isProduction' => false, + 'isStaging' => false, + 'isDevelopment' => false, + 'isPreview' => false, + 'isCi' => true, + 'isLocal' => false, + 'getIndicatorConfig' => null, ], ], 'ddev' => [ [ - 'IS_DDEV_PROJECT' => TRUE, + 'IS_DDEV_PROJECT' => true, ], [ 'getEnvironment' => '', - 'isAcquia' => FALSE, - 'isCircleCi' => FALSE, - 'isGitHubWorkflow' => FALSE, - 'isGitLabCi' => FALSE, - 'isPantheon' => FALSE, - 'isProduction' => FALSE, - 'isStaging' => FALSE, - 'isDevelopment' => FALSE, - 'isPreview' => FALSE, - 'isCi' => FALSE, - 'isLocal' => TRUE, + 'isAcquia' => false, + 'isCircleCi' => false, + 'isGitHubWorkflow' => false, + 'isGitLabCi' => false, + 'isPantheon' => false, + 'isProduction' => false, + 'isStaging' => false, + 'isDevelopment' => false, + 'isPreview' => false, + 'isCi' => false, + 'isLocal' => true, 'getIndicatorConfig' => [ 'name' => 'Local', 'bg_color' => '#ffffff', @@ -365,17 +369,17 @@ public function providerEnvironment(): array { ], [ 'getEnvironment' => '', - 'isAcquia' => FALSE, - 'isCircleCi' => FALSE, - 'isGitHubWorkflow' => FALSE, - 'isGitLabCi' => FALSE, - 'isPantheon' => FALSE, - 'isProduction' => FALSE, - 'isStaging' => FALSE, - 'isDevelopment' => FALSE, - 'isPreview' => FALSE, - 'isCi' => FALSE, - 'isLocal' => TRUE, + 'isAcquia' => false, + 'isCircleCi' => false, + 'isGitHubWorkflow' => false, + 'isGitLabCi' => false, + 'isPantheon' => false, + 'isProduction' => false, + 'isStaging' => false, + 'isDevelopment' => false, + 'isPreview' => false, + 'isCi' => false, + 'isLocal' => true, 'getIndicatorConfig' => [ 'name' => 'Local', 'bg_color' => '#ffffff', From 78240a5dea398e3f7213d3eabf9797759fb5dc3c Mon Sep 17 00:00:00 2001 From: Dave Reid Date: Tue, 27 Jun 2023 09:48:23 -0500 Subject: [PATCH 09/20] Fixing more coding standards. --- .codeclimate.yml | 2 ++ composer.json | 1 + src/Environment.php | 1 - src/Environment/DefaultEnvironment.php | 1 - src/Environment/GitHubWorkflow.php | 1 - src/Environment/GitLabCi.php | 1 - src/Environment/Pantheon.php | 1 - src/Environment/Tugboat.php | 1 - tests/src/EnvironmentTest.php | 1 - 9 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.codeclimate.yml b/.codeclimate.yml index 969ad6c..e707e1d 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -1,6 +1,8 @@ plugins: phpcodesniffer: enabled: true + config: + standard: "PSR1,PSR2" phpmd: enabled: true exclude_patterns: diff --git a/composer.json b/composer.json index f812862..91ec58f 100644 --- a/composer.json +++ b/composer.json @@ -50,6 +50,7 @@ "@phpstan", "@phpunit" ], + "phpcs": "vendor/bin/phpcs --standard=PSR1,PSR2 src tests", "phpstan": "vendor/bin/phpstan analyse src tests --level 5", "phpunit": "vendor/bin/phpunit tests/src --verbose --coverage-text" }, diff --git a/src/Environment.php b/src/Environment.php index d23bc6f..8bb8f65 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -169,5 +169,4 @@ public static function getComposerLockFilename(): string $composer_filename = static::getComposerFilename(); return pathinfo($composer_filename, PATHINFO_FILENAME) . '.lock'; } - } diff --git a/src/Environment/DefaultEnvironment.php b/src/Environment/DefaultEnvironment.php index 1302dfe..4fbb452 100644 --- a/src/Environment/DefaultEnvironment.php +++ b/src/Environment/DefaultEnvironment.php @@ -198,5 +198,4 @@ public static function getIndicatorConfig(): ?array // Unknown environment condition. return null; } - } diff --git a/src/Environment/GitHubWorkflow.php b/src/Environment/GitHubWorkflow.php index 6e4a2a6..82e11bc 100644 --- a/src/Environment/GitHubWorkflow.php +++ b/src/Environment/GitHubWorkflow.php @@ -22,5 +22,4 @@ public static function getEnvironment(): string { return static::CI; } - } diff --git a/src/Environment/GitLabCi.php b/src/Environment/GitLabCi.php index 88d5934..df3fee1 100644 --- a/src/Environment/GitLabCi.php +++ b/src/Environment/GitLabCi.php @@ -22,5 +22,4 @@ public static function getEnvironment(): string { return static::CI; } - } diff --git a/src/Environment/Pantheon.php b/src/Environment/Pantheon.php index d19853b..c3a7cc0 100644 --- a/src/Environment/Pantheon.php +++ b/src/Environment/Pantheon.php @@ -45,5 +45,4 @@ public static function isMultidev(): bool && !static::isCi() && !static::isLocal(); } - } diff --git a/src/Environment/Tugboat.php b/src/Environment/Tugboat.php index 7769760..81c69b2 100644 --- a/src/Environment/Tugboat.php +++ b/src/Environment/Tugboat.php @@ -22,5 +22,4 @@ public static function isPreview(): bool { return true; } - } diff --git a/tests/src/EnvironmentTest.php b/tests/src/EnvironmentTest.php index 856a635..fa54f2e 100644 --- a/tests/src/EnvironmentTest.php +++ b/tests/src/EnvironmentTest.php @@ -398,5 +398,4 @@ public function providerEnvironment(): array ] ]; } - } From 41b4fcae8ee636c3038baada43f98c4f98c72663 Mon Sep 17 00:00:00 2001 From: Dave Reid Date: Tue, 27 Jun 2023 09:49:52 -0500 Subject: [PATCH 10/20] Move classes back down to src directory. --- src/{Environment => }/Acquia.php | 2 +- src/{Environment => }/CircleCi.php | 2 +- src/{Environment => }/DefaultEnvironment.php | 4 +--- src/Environment.php | 8 -------- src/{Environment => }/GitHubWorkflow.php | 2 +- src/{Environment => }/GitLabCi.php | 2 +- src/{Environment => }/Pantheon.php | 2 +- src/{Environment => }/Tugboat.php | 2 +- 8 files changed, 7 insertions(+), 17 deletions(-) rename src/{Environment => }/Acquia.php (90%) rename src/{Environment => }/CircleCi.php (87%) rename src/{Environment => }/DefaultEnvironment.php (97%) rename src/{Environment => }/GitHubWorkflow.php (89%) rename src/{Environment => }/GitLabCi.php (88%) rename src/{Environment => }/Pantheon.php (95%) rename src/{Environment => }/Tugboat.php (88%) diff --git a/src/Environment/Acquia.php b/src/Acquia.php similarity index 90% rename from src/Environment/Acquia.php rename to src/Acquia.php index 25e3e1c..1658b48 100644 --- a/src/Environment/Acquia.php +++ b/src/Acquia.php @@ -1,6 +1,6 @@ Date: Tue, 27 Jun 2023 09:58:23 -0500 Subject: [PATCH 11/20] Skip routing get through DefaultEnvironment. --- src/DefaultEnvironment.php | 6 +----- src/Environment.php | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/DefaultEnvironment.php b/src/DefaultEnvironment.php index 63dcded..ef2a027 100644 --- a/src/DefaultEnvironment.php +++ b/src/DefaultEnvironment.php @@ -61,11 +61,7 @@ class DefaultEnvironment */ public static function get(string $name) { - static $cache = []; - if (!array_key_exists($name, $cache)) { - $cache[$name] = getenv($name); - } - return $cache[$name]; + return Environment::get($name); } /** diff --git a/src/Environment.php b/src/Environment.php index 170512d..18cfac9 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -5,7 +5,6 @@ /** * Helpers for working with the Drupal environment. * - * @method static mixed get(string $name) * @method static string getEnvironment() * @method static bool isAcquia() * @method static bool isPantheon() @@ -41,17 +40,17 @@ class Environment * @return string * The class name. */ - public static function getEnvironmentClass() + public static function getEnvironmentClass(): string { static $class; if (!isset($class)) { - if ($class = getenv('DRUPAL_ENVIRONMENT_CLASS')) { + if ($class = static::get('DRUPAL_ENVIRONMENT_CLASS')) { // Do nothing. The class was assigned in the if. } else { // Intentionally re-assigning the class variable here so that a match // breaks the foreach loop, or we fall back to the default class. foreach (static::CLASSES as $class) { - if (getenv($class::ENVIRONMENT_NAME)) { + if (static::get($class::ENVIRONMENT_NAME)) { break; } } @@ -75,6 +74,24 @@ public static function __callStatic(string $name, array $arguments) return $class::$name(...$arguments); } + /** + * Get an environment variable. + * + * @param string $name + * The name of the environment variable to retrieve. + * + * @return mixed + * The environment variable, if it's set. + */ + public static function get(string $name) + { + static $cache = []; + if (!array_key_exists($name, $cache)) { + $cache[$name] = getenv($name); + } + return $cache[$name]; + } + /** * Determine if this is a local environment. * From cefe481375ba3e80fce1dc6ce4d86751981e561d Mon Sep 17 00:00:00 2001 From: Dave Reid Date: Tue, 27 Jun 2023 09:59:21 -0500 Subject: [PATCH 12/20] Mark the individual environment classes as internal. --- src/Acquia.php | 2 ++ src/CircleCi.php | 2 ++ src/DefaultEnvironment.php | 2 ++ src/GitHubWorkflow.php | 2 ++ src/GitLabCi.php | 2 ++ src/Pantheon.php | 2 ++ src/Tugboat.php | 2 ++ 7 files changed, 14 insertions(+) diff --git a/src/Acquia.php b/src/Acquia.php index 1658b48..1a87258 100644 --- a/src/Acquia.php +++ b/src/Acquia.php @@ -11,6 +11,8 @@ * @todo Add isPreview() support. * @todo Should the 'ide' environment be detected as local? * @todo Add support for https://docs.acquia.com/ra/environment.html + * + * @internal */ class Acquia extends DefaultEnvironment { diff --git a/src/CircleCi.php b/src/CircleCi.php index 2215831..1a27564 100644 --- a/src/CircleCi.php +++ b/src/CircleCi.php @@ -6,6 +6,8 @@ * The CircleCI environment specifics. * * @see https://circleci.com/docs/variables/ + * + * @internal */ class CircleCi extends DefaultEnvironment { diff --git a/src/DefaultEnvironment.php b/src/DefaultEnvironment.php index ef2a027..1f0c55e 100644 --- a/src/DefaultEnvironment.php +++ b/src/DefaultEnvironment.php @@ -4,6 +4,8 @@ /** * The standard environment. + * + * @internal */ class DefaultEnvironment { diff --git a/src/GitHubWorkflow.php b/src/GitHubWorkflow.php index f0d4c3f..79a3496 100644 --- a/src/GitHubWorkflow.php +++ b/src/GitHubWorkflow.php @@ -6,6 +6,8 @@ * The GitHub Workflow environment specifics. * * @see https://docs.github.com/en/actions/learn-github-actions/variables + * + * @internal */ class GitHubWorkflow extends DefaultEnvironment { diff --git a/src/GitLabCi.php b/src/GitLabCi.php index 2562ff0..544b977 100644 --- a/src/GitLabCi.php +++ b/src/GitLabCi.php @@ -6,6 +6,8 @@ * The GitlabCi environment specifics. * * @see https://docs.gitlab.com/ee/ci/variables/predefined_variables.html + * + * @internal */ class GitLabCi extends DefaultEnvironment { diff --git a/src/Pantheon.php b/src/Pantheon.php index 09e2292..e4879f7 100644 --- a/src/Pantheon.php +++ b/src/Pantheon.php @@ -7,6 +7,8 @@ * * @see https://docs.pantheon.io/pantheon-workflow * @see https://docs.pantheon.io/guides/multidev + * + * @internal */ class Pantheon extends DefaultEnvironment { diff --git a/src/Tugboat.php b/src/Tugboat.php index 1c6f5f2..722b2c3 100644 --- a/src/Tugboat.php +++ b/src/Tugboat.php @@ -6,6 +6,8 @@ * The Tugboat environment specifics. * * @see https://docs.tugboatqa.com/reference/environment-variables/ + * + * @internal */ class Tugboat extends DefaultEnvironment { From 5ef91ae91425c011393f4e708fca5c85ec803e2d Mon Sep 17 00:00:00 2001 From: Dave Reid Date: Tue, 27 Jun 2023 10:29:46 -0500 Subject: [PATCH 13/20] Remove davereid from namespace. --- composer.json | 9 ++++++--- src/Acquia.php | 2 +- src/CircleCi.php | 2 +- src/DefaultEnvironment.php | 2 +- src/Environment.php | 2 +- src/GitHubWorkflow.php | 2 +- src/GitLabCi.php | 2 +- src/Pantheon.php | 2 +- src/Tugboat.php | 2 +- tests/src/EnvironmentTest.php | 12 +++++++----- 10 files changed, 21 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index 91ec58f..24f4323 100644 --- a/composer.json +++ b/composer.json @@ -32,12 +32,12 @@ }, "autoload": { "psr-4": { - "Davereid\\DrupalEnvironment\\": "src/" + "DrupalEnvironment\\": "src/" } }, "autoload-dev": { "psr-4": { - "Davereid\\DrupalEnvironment\\Tests\\": "tests/src/" + "DrupalEnvironment\\Tests\\": "tests/src/" } }, "extra": { @@ -46,8 +46,11 @@ } }, "scripts": { + "lint": [ + "@phpcs", + "@phpstan" + ], "test": [ - "@phpstan", "@phpunit" ], "phpcs": "vendor/bin/phpcs --standard=PSR1,PSR2 src tests", diff --git a/src/Acquia.php b/src/Acquia.php index 1a87258..49f1581 100644 --- a/src/Acquia.php +++ b/src/Acquia.php @@ -1,6 +1,6 @@ null, 'GITHUB_WORKFLOW' => null, ]; - $originals = []; - $this->setEnvironmentVariables($variables, $originals); + $this->setEnvironmentVariables($variables); foreach ($method_tests as $name => $expected) { $this->assertSame($expected, Environment::$name(), "Asserting Environment::$name"); } - $this->setEnvironmentVariables($originals); } /** + * Set environment variables manually for testing. + * * @param array $variables + * The variable values to set keyed by name. * @param array|null $originals + * If provided will be populated with the original variable values keyed by name. */ protected function setEnvironmentVariables(array $variables, ?array &$originals = null): void { From 57731d2ad889bc7acb026573d7f60ef361635a71 Mon Sep 17 00:00:00 2001 From: Dave Reid Date: Tue, 27 Jun 2023 10:34:15 -0500 Subject: [PATCH 14/20] Added test coverage for Tugboat. --- tests/src/EnvironmentTest.php | 42 +++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/tests/src/EnvironmentTest.php b/tests/src/EnvironmentTest.php index 6b4cd98..fb98d69 100644 --- a/tests/src/EnvironmentTest.php +++ b/tests/src/EnvironmentTest.php @@ -13,8 +13,6 @@ final class EnvironmentTest extends TestCase /** * Test the commandExists() method. - * - * @covers \Davereid\DrupalEnvironment\Environment::commandExists */ public function testCommandExists(): void { @@ -75,6 +73,7 @@ public function providerEnvironment(): array 'isCircleCi' => false, 'isGitHubWorkflow' => false, 'isGitLabCi' => false, + 'isTugboat' => false, 'isPantheon' => false, 'isProduction' => false, 'isStaging' => false, @@ -98,6 +97,7 @@ public function providerEnvironment(): array 'isCircleCi' => false, 'isGitHubWorkflow' => false, 'isGitLabCi' => false, + 'isTugboat' => false, 'isPantheon' => false, 'isProduction' => true, 'isStaging' => false, @@ -122,6 +122,7 @@ public function providerEnvironment(): array 'isCircleCi' => false, 'isGitHubWorkflow' => false, 'isGitLabCi' => false, + 'isTugboat' => false, 'isPantheon' => false, 'isProduction' => false, 'isStaging' => false, @@ -142,6 +143,7 @@ public function providerEnvironment(): array 'isCircleCi' => false, 'isGitHubWorkflow' => false, 'isGitLabCi' => false, + 'isTugboat' => false, 'isPantheon' => true, 'isProduction' => true, 'isStaging' => false, @@ -167,6 +169,7 @@ public function providerEnvironment(): array 'isCircleCi' => false, 'isGitHubWorkflow' => false, 'isGitLabCi' => false, + 'isTugboat' => false, 'isPantheon' => true, 'isProduction' => false, 'isStaging' => true, @@ -192,6 +195,7 @@ public function providerEnvironment(): array 'isCircleCi' => false, 'isGitHubWorkflow' => false, 'isGitLabCi' => false, + 'isTugboat' => false, 'isPantheon' => true, 'isProduction' => false, 'isStaging' => false, @@ -217,6 +221,7 @@ public function providerEnvironment(): array 'isCircleCi' => false, 'isGitHubWorkflow' => false, 'isGitLabCi' => false, + 'isTugboat' => false, 'isPantheon' => true, 'isProduction' => false, 'isStaging' => false, @@ -242,6 +247,7 @@ public function providerEnvironment(): array 'isCircleCi' => false, 'isGitHubWorkflow' => false, 'isGitLabCi' => false, + 'isTugboat' => false, 'isPantheon' => true, 'isProduction' => false, 'isStaging' => false, @@ -263,6 +269,7 @@ public function providerEnvironment(): array 'isCircleCi' => false, 'isGitHubWorkflow' => false, 'isGitLabCi' => false, + 'isTugboat' => false, 'isPantheon' => true, 'isProduction' => false, 'isStaging' => false, @@ -278,6 +285,32 @@ public function providerEnvironment(): array ], ], ], + 'tugboat' => [ + [ + 'TUGBOAT_PREVIEW_NAME' => 'phpunit', + ], + [ + 'getEnvironment' => 'local', + 'isAcquia' => false, + 'isCircleCi' => false, + 'isGitHubWorkflow' => false, + 'isGitLabCi' => false, + 'isTugboat' => true, + 'isPantheon' => true, + 'isProduction' => false, + 'isStaging' => false, + 'isDevelopment' => false, + 'isPreview' => true, + 'isMultidev' => false, + 'isCi' => false, + 'isLocal' => true, + 'getIndicatorConfig' => [ + 'name' => 'Preview', + 'bg_color' => '#ffffff', + 'fg_color' => '#990055', + ], + ], + ], 'circleci' => [ [ 'CI' => 'true', @@ -289,6 +322,7 @@ public function providerEnvironment(): array 'isCircleCi' => true, 'isGitHubWorkflow' => false, 'isGitLabCi' => false, + 'isTugboat' => false, 'isPantheon' => false, 'isProduction' => false, 'isStaging' => false, @@ -310,6 +344,7 @@ public function providerEnvironment(): array 'isCircleCi' => false, 'isGitHubWorkflow' => true, 'isGitLabCi' => false, + 'isTugboat' => false, 'isPantheon' => false, 'isProduction' => false, 'isStaging' => false, @@ -331,6 +366,7 @@ public function providerEnvironment(): array 'isCircleCi' => false, 'isGitHubWorkflow' => false, 'isGitLabCi' => true, + 'isTugboat' => false, 'isPantheon' => false, 'isProduction' => false, 'isStaging' => false, @@ -351,6 +387,7 @@ public function providerEnvironment(): array 'isCircleCi' => false, 'isGitHubWorkflow' => false, 'isGitLabCi' => false, + 'isTugboat' => false, 'isPantheon' => false, 'isProduction' => false, 'isStaging' => false, @@ -375,6 +412,7 @@ public function providerEnvironment(): array 'isCircleCi' => false, 'isGitHubWorkflow' => false, 'isGitLabCi' => false, + 'isTugboat' => false, 'isPantheon' => false, 'isProduction' => false, 'isStaging' => false, From 3ff61b3daf65db5418743f6eba4d3c4eec471f25 Mon Sep 17 00:00:00 2001 From: Dave Reid Date: Tue, 27 Jun 2023 10:35:45 -0500 Subject: [PATCH 15/20] Fixed test case. --- tests/src/EnvironmentTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/EnvironmentTest.php b/tests/src/EnvironmentTest.php index fb98d69..012e421 100644 --- a/tests/src/EnvironmentTest.php +++ b/tests/src/EnvironmentTest.php @@ -290,7 +290,7 @@ public function providerEnvironment(): array 'TUGBOAT_PREVIEW_NAME' => 'phpunit', ], [ - 'getEnvironment' => 'local', + 'getEnvironment' => 'phpunit', 'isAcquia' => false, 'isCircleCi' => false, 'isGitHubWorkflow' => false, From 1ebe5622fd3fd4502aa3e576a75db7b7ce1d334b Mon Sep 17 00:00:00 2001 From: Dave Reid Date: Tue, 27 Jun 2023 10:37:28 -0500 Subject: [PATCH 16/20] Added definition of isTugboat(). --- src/Environment.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Environment.php b/src/Environment.php index 4f91116..aeb680a 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -12,6 +12,7 @@ * @method static bool isStaging() * @method static bool isDevelopment() * @method static bool isPreview() + * @method static bool isTugboat() * @method static bool isCi() * @method static bool isGitHubWorkflow() * @method static bool isGitLabCi() From cdbbbdc13ed9696104421b7ba404e97c237fc4ce Mon Sep 17 00:00:00 2001 From: Dave Reid Date: Tue, 27 Jun 2023 10:46:55 -0500 Subject: [PATCH 17/20] Fixed tests. --- tests/src/EnvironmentTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/src/EnvironmentTest.php b/tests/src/EnvironmentTest.php index 012e421..faf1c1d 100644 --- a/tests/src/EnvironmentTest.php +++ b/tests/src/EnvironmentTest.php @@ -296,14 +296,13 @@ public function providerEnvironment(): array 'isGitHubWorkflow' => false, 'isGitLabCi' => false, 'isTugboat' => true, - 'isPantheon' => true, + 'isPantheon' => false, 'isProduction' => false, 'isStaging' => false, 'isDevelopment' => false, 'isPreview' => true, - 'isMultidev' => false, 'isCi' => false, - 'isLocal' => true, + 'isLocal' => false, 'getIndicatorConfig' => [ 'name' => 'Preview', 'bg_color' => '#ffffff', From 7e3e3134a70fe15cc28971f3e38ec9d33af36fc4 Mon Sep 17 00:00:00 2001 From: Dave Reid Date: Tue, 27 Jun 2023 10:47:34 -0500 Subject: [PATCH 18/20] Add composer run lint to CI job. --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e935dbe..494370c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,6 +36,7 @@ jobs: - run: composer diagnose || true - run: composer install - run: composer audit + - run: composer run lint - run: composer run test - name: Test & publish code coverage if: ${{ matrix.php == '8.2' && matrix.os == 'ubuntu-latest' }} From 0c58a469b54c430539716e456a4e565e1b30782c Mon Sep 17 00:00:00 2001 From: Dave Reid Date: Tue, 27 Jun 2023 10:50:23 -0500 Subject: [PATCH 19/20] Fix a phpmd issue. --- src/Environment.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Environment.php b/src/Environment.php index aeb680a..f7feca0 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -176,7 +176,7 @@ public static function getComposerFilename(): string */ public static function getComposerLockFilename(): string { - $composer_filename = static::getComposerFilename(); - return pathinfo($composer_filename, PATHINFO_FILENAME) . '.lock'; + $filename = static::getComposerFilename(); + return pathinfo($filename, PATHINFO_FILENAME) . '.lock'; } } From 4b60b5d1602a217a5ad1631c3e3268821f4cf78e Mon Sep 17 00:00:00 2001 From: Dave Reid Date: Tue, 27 Jun 2023 10:51:03 -0500 Subject: [PATCH 20/20] Disable phpmd for now. --- .codeclimate.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.codeclimate.yml b/.codeclimate.yml index e707e1d..184634f 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -4,6 +4,6 @@ plugins: config: standard: "PSR1,PSR2" phpmd: - enabled: true + enabled: false exclude_patterns: - "tests/"