LoadEnvironmentVariablesTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace Illuminate\Tests\Foundation\Bootstrap;
  3. use Illuminate\Foundation\Application;
  4. use Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables;
  5. use Mockery as m;
  6. use PHPUnit\Framework\TestCase;
  7. class LoadEnvironmentVariablesTest extends TestCase
  8. {
  9. protected function tearDown(): void
  10. {
  11. unset($_ENV['FOO'], $_SERVER['FOO']);
  12. putenv('FOO');
  13. m::close();
  14. }
  15. protected function getAppMock($file)
  16. {
  17. $app = m::mock(Application::class);
  18. $app->shouldReceive('configurationIsCached')
  19. ->once()->with()->andReturn(false);
  20. $app->shouldReceive('runningInConsole')
  21. ->once()->with()->andReturn(false);
  22. $app->shouldReceive('environmentPath')
  23. ->once()->with()->andReturn(__DIR__.'/../fixtures');
  24. $app->shouldReceive('environmentFile')
  25. ->once()->with()->andReturn($file);
  26. return $app;
  27. }
  28. public function testCanLoad()
  29. {
  30. $this->expectOutputString('');
  31. (new LoadEnvironmentVariables)->bootstrap($this->getAppMock('.env'));
  32. $this->assertSame('BAR', env('FOO'));
  33. $this->assertSame('BAR', getenv('FOO'));
  34. $this->assertSame('BAR', $_ENV['FOO']);
  35. $this->assertSame('BAR', $_SERVER['FOO']);
  36. }
  37. public function testCanFailSilent()
  38. {
  39. $this->expectOutputString('');
  40. (new LoadEnvironmentVariables)->bootstrap($this->getAppMock('BAD_FILE'));
  41. }
  42. }