StoreTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace Dotenv\Tests;
  3. use Dotenv\Store\File\Paths;
  4. use Dotenv\Store\File\Reader;
  5. use Dotenv\Store\StoreBuilder;
  6. use PHPUnit\Framework\TestCase;
  7. class StoreTest extends TestCase
  8. {
  9. /**
  10. * @var string
  11. */
  12. private $folder;
  13. /**
  14. * @before
  15. */
  16. public function setUpTest()
  17. {
  18. $this->folder = dirname(__DIR__).'/fixtures/env';
  19. }
  20. public function testBasicReadDirect()
  21. {
  22. self::assertSame(
  23. [
  24. $this->folder.DIRECTORY_SEPARATOR.'.env' => "FOO=bar\nBAR=baz\nSPACED=\"with spaces\"\n\nNULL=\n",
  25. ],
  26. Reader::read(
  27. Paths::filePaths([$this->folder], ['.env'])
  28. )
  29. );
  30. }
  31. public function testBasicRead()
  32. {
  33. $builder = StoreBuilder::create()
  34. ->withPaths([$this->folder])
  35. ->withNames(['.env']);
  36. self::assertSame(
  37. "FOO=bar\nBAR=baz\nSPACED=\"with spaces\"\n\nNULL=\n",
  38. $builder->make()->read()
  39. );
  40. }
  41. public function testFileReadMultipleShortCircuitModeDirect()
  42. {
  43. self::assertSame(
  44. [
  45. $this->folder.DIRECTORY_SEPARATOR.'.env' => "FOO=bar\nBAR=baz\nSPACED=\"with spaces\"\n\nNULL=\n",
  46. ],
  47. Reader::read(
  48. Paths::filePaths([$this->folder], ['.env', 'example.env'])
  49. )
  50. );
  51. }
  52. public function testFileReadMultipleShortCircuitMode()
  53. {
  54. $builder = StoreBuilder::create()
  55. ->withPaths([$this->folder])
  56. ->withNames(['.env', 'example.env'])
  57. ->shortCircuit();
  58. self::assertSame(
  59. "FOO=bar\nBAR=baz\nSPACED=\"with spaces\"\n\nNULL=\n",
  60. $builder->make()->read()
  61. );
  62. }
  63. public function testFileReadMultipleWithoutShortCircuitModeDirect()
  64. {
  65. self::assertSame(
  66. [
  67. $this->folder.DIRECTORY_SEPARATOR.'.env' => "FOO=bar\nBAR=baz\nSPACED=\"with spaces\"\n\nNULL=\n",
  68. $this->folder.DIRECTORY_SEPARATOR.'example.env' => "EG=\"example\"\n",
  69. ],
  70. Reader::read(
  71. Paths::filePaths([$this->folder], ['.env', 'example.env']),
  72. false
  73. )
  74. );
  75. }
  76. public function testFileReadMultipleWithoutShortCircuitMode()
  77. {
  78. $builder = StoreBuilder::create()
  79. ->withPaths([$this->folder])
  80. ->withNames(['.env', 'example.env']);
  81. self::assertSame(
  82. "FOO=bar\nBAR=baz\nSPACED=\"with spaces\"\n\nNULL=\n\nEG=\"example\"\n",
  83. $builder->make()->read()
  84. );
  85. }
  86. }