env returns an environment variable

This commit is contained in:
Oliver Davies 2019-05-21 12:37:38 +01:00
parent 61e3dfa0ec
commit 52d8e4c626
2 changed files with 30 additions and 0 deletions

View file

@ -1,2 +1,8 @@
<?php
if (!function_exists('env')) {
function env(string $name): ?string
{
return $_ENV[$name];
}
}

24
tests/EnvironmentTest.php Normal file
View file

@ -0,0 +1,24 @@
<?php
namespace Tests\Opdavies\PhpHelpers;
use PHPUnit\Framework\TestCase;
class EnvironmentTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
// Ensure that the enviornment variables are empty before each test.
$_ENV = [];
}
/** @test */
public function it_gets_an_environment_variable()
{
$_ENV['APP_ENV'] = 'prod';
$this->assertSame('prod', env('APP_ENV'));
}
}