Skip to content

Commit

Permalink
Testing env function
Browse files Browse the repository at this point in the history
  • Loading branch information
lonnieezell committed Jan 17, 2017
1 parent 726567d commit e69777b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions system/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ function view_cell(string $library, $params = null, int $ttl = 0, string $cacheN
function env(string $key, $default = null)
{
$value = getenv($key);
if ($value === false)
{
$value = $_ENV[$key] ?? $_SERVER[$key] ?? false;
}

// Not found? Return the default value
if ($value === false)
Expand Down
19 changes: 19 additions & 0 deletions tests/system/CommonFunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class CommomFunctionsTest extends \CIUnitTestCase

public function setUp()
{
unset($_ENV['foo'], $_SERVER['foo']);
}

//--------------------------------------------------------------------
Expand Down Expand Up @@ -42,4 +43,22 @@ public function testStringifyJsAttributes()

// ------------------------------------------------------------------------

public function testEnvReturnsDefault()
{
$this->assertEquals('baz', env('foo', 'baz'));
}

public function testEnvGetsFromSERVER()
{
$_SERVER['foo'] = 'bar';

$this->assertEquals('bar', env('foo', 'baz'));
}

public function testEnvGetsFromENV()
{
$_ENV['foo'] = 'bar';

$this->assertEquals('bar', env('foo', 'baz'));
}
}

0 comments on commit e69777b

Please sign in to comment.