From f648e2a6b139ed9b30900bfd74359ffc3cf6d8c7 Mon Sep 17 00:00:00 2001 From: andrewbelcher Date: Wed, 12 Jan 2022 14:02:17 +0000 Subject: [PATCH] Add environment type and fix onProduction. --- src/Config.php | 7 ++++--- tests/ConfigTest.php | 28 ++++------------------------ 2 files changed, 8 insertions(+), 27 deletions(-) diff --git a/src/Config.php b/src/Config.php index 8fa32ea..d0ad472 100644 --- a/src/Config.php +++ b/src/Config.php @@ -35,6 +35,8 @@ * The Git branch name. * @property-read string $environment * The environment ID (usually the Git branch plus a hash). + * @property-read string $environmentType + * The environment type. * @property-read string $documentRoot * The absolute path to the web root of the application. * @property-read string $smtpHost @@ -76,6 +78,7 @@ class Config protected $directVariablesRuntime = [ 'branch' => 'BRANCH', 'environment' => 'ENVIRONMENT', + 'environmentType' => 'ENVIRONMENT_TYPE', 'documentRoot' => 'DOCUMENT_ROOT', 'smtpHost' => 'SMTP_HOST', ]; @@ -437,9 +440,7 @@ public function onProduction() : bool return false; } - $prodBranch = $this->onDedicated() ? 'production' : 'master'; - - return $this->getValue('BRANCH') == $prodBranch; + return $this->getValue('ENVIRONMENT_TYPE') == 'production'; } /** diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 862ea33..0519ff7 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -200,45 +200,25 @@ public function test_ondedicated_returns_false_on_standard() : void $this->assertFalse($config->onDedicated()); } - public function test_onproduction_on_dedicated_prod_is_true() : void + public function test_onproduction_prod_is_true() : void { $env = $this->mockEnvironmentDeploy; - $env['PLATFORM_MODE'] = 'enterprise'; - $env['PLATFORM_BRANCH'] = 'production'; + $env['PLATFORM_ENVIRONMENT_TYPE'] = 'production'; $config = new Config($env); $this->assertTrue($config->onProduction()); } - public function test_onproduction_on_dedicated_stg_is_false() : void + public function test_onproduction_stg_is_false() : void { $env = $this->mockEnvironmentDeploy; - $env['PLATFORM_MODE'] = 'enterprise'; - $env['PLATFORM_BRANCH'] = 'staging'; + $env['PLATFORM_ENVIRONMENT_TYPE'] = 'staging'; $config = new Config($env); $this->assertFalse($config->onProduction()); } - public function test_onproduction_on_standard_prod_is_true() : void - { - $env = $this->mockEnvironmentDeploy; - $env['PLATFORM_BRANCH'] = 'master'; - $config = new Config($env); - - $this->assertTrue($config->onProduction()); - } - - public function test_onproduction_on_standard_stg_is_false() : void - { - // The fixture has a non-master branch set by default. - $env = $this->mockEnvironmentDeploy; - $config = new Config($env); - - $this->assertFalse($config->onProduction()); - } - public function test_credentials_existing_relationship_returns() : void { $env = $this->mockEnvironmentDeploy;