Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add environment type and fix Config::onProduction #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -76,6 +78,7 @@ class Config
protected $directVariablesRuntime = [
'branch' => 'BRANCH',
'environment' => 'ENVIRONMENT',
'environmentType' => 'ENVIRONMENT_TYPE',
'documentRoot' => 'DOCUMENT_ROOT',
'smtpHost' => 'SMTP_HOST',
];
Expand Down Expand Up @@ -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';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like some legacy environments will not have that variable, so we need to keep the current logic as backwards compatibility here.

}

/**
Expand Down
28 changes: 4 additions & 24 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down