Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions tests/Dotenv/DotenvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,13 @@ public function testDotenvTrimmedKeys()
self::assertSame('no space', $_SERVER['QWHITESPACE']);
}

public function testDotenvLoadDoesNotOverwriteEnv()
public function testDotenvImmutableLoadIgnoresPutenv()
{
\putenv('IMMUTABLE=true');
$dotenv = Dotenv::createImmutable(self::$folder, 'immutable.env');
$dotenv->load();
self::assertSame(['IMMUTABLE' => 'false'], $dotenv->load());
self::assertSame('false', $_ENV['IMMUTABLE']);
self::assertSame('false', $_SERVER['IMMUTABLE']);
self::assertSame('true', \getenv('IMMUTABLE'));
}

Expand Down Expand Up @@ -411,6 +413,27 @@ public function testDotenvParseStripsUtf8ByteOrderMark()
self::assertSame(['B' => '3'], Dotenv::parse("\xEF\xBB\xBF\nB=3"));
}

public function testDotenvParseInterpolationAfterMultibyteText()
{
self::assertSame(
['X' => 'Y', 'FOO' => 'ĀĀĀY'],
Dotenv::parse("X=Y\nFOO=\"ĀĀĀ\${X}\"")
);
}

public function testDotenvParseKeepsEscapedNestedVariableLiteral()
{
self::assertSame(
['B' => 'hi', 'FOO' => '$A ${B}'],
Dotenv::parse("B=hi\nFOO=\"\$A \\\${B}\"")
);
}

public function testDotenvParseIndentedComment()
{
self::assertSame(['A' => '1'], Dotenv::parse(" # c\nA=1"));
}

public function testDotenvParseEmptyCase()
{
$output = Dotenv::parse('');
Expand Down
8 changes: 7 additions & 1 deletion tests/Dotenv/Parser/EntryParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public function testNullParse()
$this->checkEmptyResult($result, 'FOO');
}

public function testNullParseOtherName()
{
$result = EntryParser::parse('BAR');
$this->checkEmptyResult($result, 'BAR');
}

public function testUnicodeNameParse()
{
$result = EntryParser::parse('FOOƱ=BAZ');
Expand Down Expand Up @@ -289,7 +295,7 @@ private function checkEmptyResult(Result $result, string $name)

$entry = $result->success()->get();
self::assertInstanceOf(Entry::class, $entry);
self::assertSame('FOO', $entry->getName());
self::assertSame($name, $entry->getName());
self::assertFalse($entry->getValue()->isDefined());
}

Expand Down
7 changes: 4 additions & 3 deletions tests/Dotenv/Parser/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ public function testParserInstanceOf()

public function testFullParse()
{
$result = (new Parser())->parse("FOO=BAR\nFOO\nFOO=\"BAR \n\"\nFOO=\"\\n\"");
$result = (new Parser())->parse("FOO=BAR\nFOO\nFOO=\"BAR \n\"\nFOO=\"\\n\"\nBAR");

self::assertIsArray($result);
self::assertCount(4, $result);
self::assertCount(5, $result);

$this->checkPositiveEntry($result[0], 'FOO', 'BAR');
$this->checkEmptyEntry($result[1], 'FOO');
$this->checkPositiveEntry($result[2], 'FOO', "BAR \n");
$this->checkPositiveEntry($result[3], 'FOO', "\n");
$this->checkEmptyEntry($result[4], 'BAR');
}

public function testBadEscapeParse()
Expand Down Expand Up @@ -100,7 +101,7 @@ private function checkPositiveEntry(Entry $entry, string $name, string $chars, a
private function checkEmptyEntry(Entry $entry, string $name)
{
self::assertInstanceOf(Entry::class, $entry);
self::assertSame('FOO', $entry->getName());
self::assertSame($name, $entry->getName());
self::assertFalse($entry->getValue()->isDefined());
}
}
26 changes: 26 additions & 0 deletions tests/Dotenv/Store/StoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,30 @@ public function testFileReadWithUtf8WithBomEncoding()
)
);
}

public function testFileReadWithUtf16LeWithBomEncoding()
{
$builder = StoreBuilder::createWithNoNames()
->addPath(self::$folder)
->addName('utf16le-with-bom-encoding.env')
->fileEncoding('UTF-16LE');

self::assertSame(
"FOO=bar\nBAR=baz\n",
$builder->make()->read()
);
}

public function testFileReadWithUtf32LeWithBomEncoding()
{
$builder = StoreBuilder::createWithNoNames()
->addPath(self::$folder)
->addName('utf32le-with-bom-encoding.env')
->fileEncoding('UTF-32LE');

self::assertSame(
"FOO=bar\nBAR=baz\n",
$builder->make()->read()
);
}
}
Binary file added tests/fixtures/env/utf16le-with-bom-encoding.env
Binary file not shown.
Binary file added tests/fixtures/env/utf32le-with-bom-encoding.env
Binary file not shown.
Loading