Skip to content

Commit

Permalink
Fixed legacy constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell committed Dec 12, 2019
1 parent 2508028 commit a6142d2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/Dotenv.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

/**
Expand Down
35 changes: 31 additions & 4 deletions tests/Dotenv/DotenvTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

use Dotenv\Dotenv;
use Dotenv\Loader\Loader;
use Dotenv\Repository\RepositoryBuilder;
use Dotenv\Store\StoreBuilder;
use PHPUnit\Framework\TestCase;

class DotenvTest extends TestCase
Expand Down Expand Up @@ -267,10 +270,34 @@ public function testMutlilineLoading()
$this->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());
}
}

0 comments on commit a6142d2

Please sign in to comment.