Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
added tests for #88
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbannert committed Oct 1, 2018
1 parent 46bb997 commit b4d60b8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
8 changes: 6 additions & 2 deletions src/Automatic/Configurator/EnvConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ public function configure(PackageContract $package): void
continue;
}

$value = self::expandTargetDir($this->options, (string) $value);
if (\is_string($value)) {
$value = self::expandTargetDir($this->options, $value);
} elseif (\filter_var($value, \FILTER_VALIDATE_BOOLEAN, \FILTER_NULL_ON_FAILURE) !== null) {
$value = \var_export($value, true);
}

if (\strpbrk($value, " \t\n&!\"") !== false) {
$value = '"' . \str_replace(['\\', '"', "\t", "\n"], ['\\\\', '\\"', '\t', '\n'], $value) . '"';
}

$data .= "${key}=${value}\n";
$data .= $key . '=' . $value . "\n";
}

if (! \file_exists($this->path->getWorkingDir() . \DIRECTORY_SEPARATOR . '.env')) {
Expand Down
25 changes: 14 additions & 11 deletions tests/Automatic/Configurator/EnvConfiguratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,18 @@ public function testConfigure(): void
$package->setConfig([
ConfiguratorContract::TYPE => [
EnvConfigurator::getName() => [
'APP_ENV' => 'test bar',
'APP_DEBUG' => '0',
'APP_PARAGRAPH' => "foo\n\"bar\"\\t",
'DATABASE_URL' => 'mysql://[email protected]:3306/narrowspark?charset=utf8mb4&serverVersion=5.7',
'MAILER_URL' => 'null://localhost',
'MAILER_USER' => 'narrow',
'#1' => 'Comment 1',
'#2' => 'Comment 3',
'#TRUSTED_SECRET' => 's3cretf0rt3st"<>',
'APP_SECRET' => 's3cretf0rt3st"<>',
'APP_ENV' => 'test bar',
'APP_DEBUG' => '0',
'APP_PARAGRAPH' => "foo\n\"bar\"\\t",
'DATABASE_URL' => 'mysql://[email protected]:3306/narrowspark?charset=utf8mb4&serverVersion=5.7',
'MAILER_URL' => 'null://localhost',
'MAILER_USER' => 'narrow',
'#1' => 'Comment 1',
'#2' => 'Comment 3',
'#TRUSTED_SECRET' => 's3cretf0rt3st"<>',
'APP_SECRET' => 's3cretf0rt3st"<>',
'BOOL' => false,
'VALID_NUMBER_TRUE' => 1,
],
],
]);
Expand All @@ -107,10 +109,11 @@ public function testConfigure(): void
# Comment 3
#TRUSTED_SECRET="s3cretf0rt3st\"<>"
APP_SECRET="s3cretf0rt3st\"<>"
BOOL=false
VALID_NUMBER_TRUE=1
###< fixtures/test ###

EOF;

// Skip on second call
$this->configurator->configure($package);

Expand Down

0 comments on commit b4d60b8

Please sign in to comment.