diff --git a/features/fill-variables.feature b/features/fill-variables.feature index 5659b38..548d183 100644 --- a/features/fill-variables.feature +++ b/features/fill-variables.feature @@ -107,3 +107,21 @@ Feature: """ A_BASE64_VALUE=abc123= """ + + Scenario: It displays correctly boolean with 1 and 0 + Given the file ".env.dist" contains: + """ + ## Something + MY_VARIABLE=0 + """ + And the file ".env" contains: + """ + MY_VARIABLE= + """ + When I run the companion with the following answers: + | Let's fix this? (y) | y | + | MY_VARIABLE ? (0) | 0 | + And the file ".env" should contain: + """ + MY_VARIABLE=0 + """ diff --git a/src/Companienv/Interaction/AskVariableValues.php b/src/Companienv/Interaction/AskVariableValues.php index d2c5c61..91744f1 100644 --- a/src/Companienv/Interaction/AskVariableValues.php +++ b/src/Companienv/Interaction/AskVariableValues.php @@ -15,10 +15,10 @@ class AskVariableValues implements Extension public function getVariableValue(Companion $companion, Block $block, Variable $variable) { $definedVariablesHash = $companion->getDefinedVariablesHash(); - $defaultValue = $definedVariablesHash[$variable->getName()] ?? $variable->getValue() ?: $variable->getValue(); + $defaultValue = ($definedVariablesHash[$variable->getName()] ?? $variable->getValue()) ?: $variable->getValue(); $question = sprintf('%s ? ', $variable->getName()); - if ($defaultValue) { + if ($defaultValue !== '') { $question .= '('.$defaultValue.') '; }