Skip to content
This repository was archived by the owner on Feb 15, 2023. It is now read-only.

Commit e40b0ae

Browse files
committed
Test the APP_ENV setting, and make sure it handles both and getenv() values.
1 parent 800c525 commit e40b0ae

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

platformsh-flex-env.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ function mapPlatformShEnvironment() : void
2626
// Default to production. You can override this value by setting
2727
// `env:APP_ENV` as a project variable, or by adding it to the
2828
// .platform.app.yaml variables block.
29-
if (!isset($_SERVER['APP_ENV'])) {
30-
$_SERVER['APP_ENV'] = 'prod';
31-
}
29+
$_SERVER['APP_ENV'] = $_SERVER['APP_ENV'] ?? (getenv('APP_ENV') ?: null) ?? 'prod';
3230

3331
if (!isset($_SERVER['DATABASE_URL'])) {
3432
mapPlatformShDatabase();

tests/FlexBridgeTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,33 @@ public function testDontChangeAppSecret()
3636
$this->assertEquals('original', $_SERVER['APP_SECRET']);
3737
}
3838

39+
public function testAppEnvAlreadySetInServer()
40+
{
41+
putenv('PLATFORM_APPLICATION=test');
42+
$_SERVER['APP_ENV'] = 'dev';
43+
44+
mapPlatformShEnvironment();
45+
46+
$this->assertEquals('dev', $_SERVER['APP_ENV']);
47+
}
48+
49+
public function testAppEnvAlreadySetInEnv()
50+
{
51+
putenv('PLATFORM_APPLICATION=test');
52+
putenv('APP_ENV=dev');
53+
54+
mapPlatformShEnvironment();
55+
56+
$this->assertEquals('dev', $_SERVER['APP_ENV']);
57+
}
58+
59+
public function testAppEnvNeedsDefault()
60+
{
61+
putenv('PLATFORM_APPLICATION=test');
62+
63+
mapPlatformShEnvironment();
64+
65+
$this->assertEquals('prod', $_SERVER['APP_ENV']);
66+
}
67+
3968
}

0 commit comments

Comments
 (0)