From a6142d226aa3609a5573a343a62d377e03d5de97 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Thu, 12 Dec 2019 20:46:02 +0000 Subject: [PATCH] Fixed legacy constructor --- src/Dotenv.php | 3 ++- tests/Dotenv/DotenvTest.php | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/Dotenv.php b/src/Dotenv.php index 337becd3..01935d5c 100644 --- a/src/Dotenv.php +++ b/src/Dotenv.php @@ -7,6 +7,7 @@ use Dotenv\Loader\LoaderInterface; use Dotenv\Repository\RepositoryBuilder; use Dotenv\Repository\RepositoryInterface; +use Dotenv\Store\FileStore; use Dotenv\Store\StoreBuilder; class Dotenv @@ -45,7 +46,7 @@ public function __construct(LoaderInterface $loader, RepositoryInterface $reposi { $this->loader = $loader; $this->repository = $repository; - $this->store = is_array($store) ? new Store($store, true) : $store; + $this->store = is_array($store) ? new FileStore($store, true) : $store; } /** diff --git a/tests/Dotenv/DotenvTest.php b/tests/Dotenv/DotenvTest.php index 9f0d98a1..9f239032 100644 --- a/tests/Dotenv/DotenvTest.php +++ b/tests/Dotenv/DotenvTest.php @@ -1,6 +1,9 @@ assertSame('https://vision.googleapis.com/v1/images:annotate?key=', getenv('TEST_EQS')); } - public function testGetEnvironmentVariablesList() + public function testLegacyConstructor() { - $dotenv = Dotenv::createImmutable($this->folder); - $names = array_keys($dotenv->load()); - $this->assertSame(['FOO', 'BAR', 'SPACED', 'NULL'], $names); + $loader = new Loader(); + $repository = RepositoryBuilder::create()->immutable()->make(); + + $dotenv = new Dotenv($loader, $repository, [$this->folder.DIRECTORY_SEPARATOR.'.env']); + + $this->assertSame([ + 'FOO' => 'bar', + 'BAR' => 'baz', + 'SPACED' => 'with spaces', + 'NULL' => '', + ], $dotenv->load()); + } + + public function testLatestConstructor() + { + $loader = new Loader(); + $repository = RepositoryBuilder::create()->immutable()->make(); + $store = StoreBuilder::create()->withPaths($this->folder)->make(); + + $dotenv = new Dotenv($loader, $repository, $store); + + $this->assertSame([ + 'FOO' => 'bar', + 'BAR' => 'baz', + 'SPACED' => 'with spaces', + 'NULL' => '', + ], $dotenv->load()); } }