[Dotenv] improved code coverage and removed unreachable code

This commit is contained in:
Stas Soroka 2019-01-06 03:17:55 +02:00 committed by Fabien Potencier
parent af9920cf10
commit 34dac7c8fd
2 changed files with 9 additions and 3 deletions

View File

@ -271,9 +271,6 @@ final class Dotenv
throw $this->createFormatException('Missing quote to end the value');
}
}
if ("\n" === $this->data[$this->cursor]) {
throw $this->createFormatException('Missing quote to end the value');
}
++$this->cursor;
$value = str_replace(array('\\"', '\r', '\n'), array('"', "\r", "\n"), $value);
$resolvedValue = $value;

View File

@ -40,8 +40,14 @@ class DotenvTest extends TestCase
array('FOO', "Missing = in the environment variable declaration in \".env\" at line 1.\n...FOO...\n ^ line 1 offset 3"),
array('FOO="foo', "Missing quote to end the value in \".env\" at line 1.\n...FOO=\"foo...\n ^ line 1 offset 8"),
array('FOO=\'foo', "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo...\n ^ line 1 offset 8"),
array('FOO=\'foo'."\n", "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo\\n...\n ^ line 1 offset 8"),
array('export FOO', "Unable to unset an environment variable in \".env\" at line 1.\n...export FOO...\n ^ line 1 offset 10"),
array('FOO=${FOO', "Unclosed braces on variable expansion in \".env\" at line 1.\n...FOO=\${FOO...\n ^ line 1 offset 9"),
array('FOO= BAR', "Whitespace are not supported before the value in \".env\" at line 1.\n...FOO= BAR...\n ^ line 1 offset 4"),
array('Стасян', "Invalid character in variable name in \".env\" at line 1.\n...Стасян...\n ^ line 1 offset 0"),
array('FOO!', "Missing = in the environment variable declaration in \".env\" at line 1.\n...FOO!...\n ^ line 1 offset 3"),
array('FOO=$(echo foo', "Missing closing parenthesis. in \".env\" at line 1.\n...FOO=$(echo foo...\n ^ line 1 offset 14"),
array('FOO=$(echo foo'."\n", "Missing closing parenthesis. in \".env\" at line 1.\n...FOO=$(echo foo\\n...\n ^ line 1 offset 14"),
);
if ('\\' !== \DIRECTORY_SEPARATOR) {
@ -64,6 +70,7 @@ class DotenvTest extends TestCase
{
putenv('LOCAL=local');
$_ENV['REMOTE'] = 'remote';
$_SERVER['SERVERVAR'] = 'servervar';
$tests = array(
// backslashes
@ -150,6 +157,7 @@ class DotenvTest extends TestCase
array('FOO=" $ "', array('FOO' => ' $ ')),
array('BAR=$LOCAL', array('BAR' => 'local')),
array('BAR=$REMOTE', array('BAR' => 'remote')),
array('BAR=$SERVERVAR', array('BAR' => 'servervar')),
array('FOO=$NOTDEFINED', array('FOO' => '')),
);
@ -222,6 +230,7 @@ class DotenvTest extends TestCase
// .env.local
$_SERVER['TEST_APP_ENV'] = 'local';
file_put_contents("$path.local", 'FOO=localBAR');
(new DotEnv())->loadEnv($path, 'TEST_APP_ENV');
$this->assertSame('localBAR', getenv('FOO'));