Skip to content

Commit

Permalink
Merge pull request #27048 from laravel/env-tests
Browse files Browse the repository at this point in the history
[5.7] Added a couple of tests for environment file loading
  • Loading branch information
taylorotwell authored Jan 3, 2019
2 parents 890c811 + 2a785cd commit 597a912
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/Foundation/Bootstrap/LoadEnvironmentVariablesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Illuminate\Tests\Foundation;

use Mockery as m;
use PHPUnit\Framework\TestCase;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables;

class LoadEnvironmentVariablesTest extends TestCase
{
public function tearDown()
{
m::close();
}

protected function getAppMock($file)
{
$app = m::mock(Application::class);

$app->shouldReceive('configurationIsCached')
->once()->with()->andReturn(false);
$app->shouldReceive('runningInConsole')
->once()->with()->andReturn(false);
$app->shouldReceive('environmentPath')
->once()->with()->andReturn(__DIR__.'/../fixtures');
$app->shouldReceive('environmentFile')
->once()->with()->andReturn($file);

return $app;
}

public function testCanLoad()
{
$this->expectOutputString('');

(new LoadEnvironmentVariables)->bootstrap($this->getAppMock('.env'));

$this->assertSame('BAR', env('FOO'));
}

public function testCanFailSilent()
{
$this->expectOutputString('');

(new LoadEnvironmentVariables)->bootstrap($this->getAppMock('BAD_FILE'));
}
}
1 change: 1 addition & 0 deletions tests/Foundation/fixtures/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FOO=BAR

0 comments on commit 597a912

Please sign in to comment.