env returns a default value

This commit is contained in:
Oliver Davies 2019-05-21 12:37:59 +01:00
parent 52d8e4c626
commit 4b543b0807
2 changed files with 14 additions and 2 deletions

View file

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

View file

@ -21,4 +21,16 @@ class EnvironmentTest extends TestCase
$this->assertSame('prod', env('APP_ENV'));
}
/** @test */
public function it_returns_a_default_value()
{
$this->assertSame('local', env('APP_ENV', 'local'));
}
/** @test */
public function it_returns_null_if_there_is_no_default()
{
$this->assertNull(env('APP_ENV'));
}
}