From 4b543b0807abd9b7705da2a2b9bd03a6f8ea59f3 Mon Sep 17 00:00:00 2001
From: Oliver Davies <oliver@oliverdavies.uk>
Date: Tue, 21 May 2019 12:37:59 +0100
Subject: [PATCH] env returns a default value

---
 src/helpers.php           |  4 ++--
 tests/EnvironmentTest.php | 12 ++++++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/helpers.php b/src/helpers.php
index 7b87a30..338a337 100644
--- a/src/helpers.php
+++ b/src/helpers.php
@@ -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;
     }
 }
diff --git a/tests/EnvironmentTest.php b/tests/EnvironmentTest.php
index b3f74cb..5200d2a 100644
--- a/tests/EnvironmentTest.php
+++ b/tests/EnvironmentTest.php
@@ -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'));
+    }
 }