Skip to content

Commit a6142d2

Browse files
Fixed legacy constructor
1 parent 2508028 commit a6142d2

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

src/Dotenv.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Dotenv\Loader\LoaderInterface;
88
use Dotenv\Repository\RepositoryBuilder;
99
use Dotenv\Repository\RepositoryInterface;
10+
use Dotenv\Store\FileStore;
1011
use Dotenv\Store\StoreBuilder;
1112

1213
class Dotenv
@@ -45,7 +46,7 @@ public function __construct(LoaderInterface $loader, RepositoryInterface $reposi
4546
{
4647
$this->loader = $loader;
4748
$this->repository = $repository;
48-
$this->store = is_array($store) ? new Store($store, true) : $store;
49+
$this->store = is_array($store) ? new FileStore($store, true) : $store;
4950
}
5051

5152
/**

tests/Dotenv/DotenvTest.php

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22

33
use Dotenv\Dotenv;
4+
use Dotenv\Loader\Loader;
5+
use Dotenv\Repository\RepositoryBuilder;
6+
use Dotenv\Store\StoreBuilder;
47
use PHPUnit\Framework\TestCase;
58

69
class DotenvTest extends TestCase
@@ -267,10 +270,34 @@ public function testMutlilineLoading()
267270
$this->assertSame('https://vision.googleapis.com/v1/images:annotate?key=', getenv('TEST_EQS'));
268271
}
269272

270-
public function testGetEnvironmentVariablesList()
273+
public function testLegacyConstructor()
271274
{
272-
$dotenv = Dotenv::createImmutable($this->folder);
273-
$names = array_keys($dotenv->load());
274-
$this->assertSame(['FOO', 'BAR', 'SPACED', 'NULL'], $names);
275+
$loader = new Loader();
276+
$repository = RepositoryBuilder::create()->immutable()->make();
277+
278+
$dotenv = new Dotenv($loader, $repository, [$this->folder.DIRECTORY_SEPARATOR.'.env']);
279+
280+
$this->assertSame([
281+
'FOO' => 'bar',
282+
'BAR' => 'baz',
283+
'SPACED' => 'with spaces',
284+
'NULL' => '',
285+
], $dotenv->load());
286+
}
287+
288+
public function testLatestConstructor()
289+
{
290+
$loader = new Loader();
291+
$repository = RepositoryBuilder::create()->immutable()->make();
292+
$store = StoreBuilder::create()->withPaths($this->folder)->make();
293+
294+
$dotenv = new Dotenv($loader, $repository, $store);
295+
296+
$this->assertSame([
297+
'FOO' => 'bar',
298+
'BAR' => 'baz',
299+
'SPACED' => 'with spaces',
300+
'NULL' => '',
301+
], $dotenv->load());
275302
}
276303
}

0 commit comments

Comments
 (0)