Skip to content

Commit

Permalink
Merge pull request #102 from louim/allow_validation_without_load
Browse files Browse the repository at this point in the history
Move loader creation to the constructor
  • Loading branch information
GrahamCampbell committed Jul 14, 2015
2 parents 1f20779 + 631e266 commit 65e5231
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/Dotenv.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Dotenv
public function __construct($path, $file = '.env')
{
$this->filePath = $this->getFilePath($path, $file);
$this->loader = new Loader($this->filePath, $immutable = true);
}

/**
Expand All @@ -35,8 +36,6 @@ public function __construct($path, $file = '.env')
*/
public function load()
{
$this->loader = new Loader($this->filePath, $immutable = true);

return $this->loader->load();
}

Expand Down
10 changes: 10 additions & 0 deletions tests/Dotenv/DotenvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,14 @@ public function testDotenvHitsLastChain()
$dotenv->load();
$dotenv->required('ASSERTVAR3')->notEmpty();
}

/**
* @expectedException RuntimeException
* @expectedExceptionMessage One or more environment variables failed assertions: foo is missing
*/
public function testDotenvValidateRequiredWithoutLoading()
{
$dotenv = new Dotenv($this->fixturesFolder, 'assertions.env');
$dotenv->required('foo');
}
}

0 comments on commit 65e5231

Please sign in to comment.