diff --git a/.travis.yml b/.travis.yml index 9d401ac..1aa662c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,4 +23,5 @@ before_script: - if [ "$dependencies" = "lowest" ]; then travis_retry composer update --prefer-lowest --prefer-stable -n; fi; script: + - vendor/bin/phpspec run - vendor/bin/behat -fprogress diff --git a/composer.json b/composer.json index 58837b0..a34c434 100644 --- a/composer.json +++ b/composer.json @@ -35,6 +35,7 @@ "bin/companienv" ], "require-dev": { - "behat/behat": "^3.4" + "behat/behat": "^3.4", + "phpspec/phpspec": "^4.3" } } diff --git a/spec/Companienv/IO/InputOutputInteractionSpec.php b/spec/Companienv/IO/InputOutputInteractionSpec.php new file mode 100644 index 0000000..60ac147 --- /dev/null +++ b/spec/Companienv/IO/InputOutputInteractionSpec.php @@ -0,0 +1,27 @@ +beConstructedWith($input, $output); + } + + function it_will_return_the_default_value() + { + $this->ask('VALUE ?', 'true')->shouldReturn('true'); + } + + function it_will_return_the_default_value_even_if_it_looks_falsy() + { + $this->ask('COUNT ?', '0')->shouldReturn('0'); + } +} diff --git a/src/Companienv/IO/InputOutputInteraction.php b/src/Companienv/IO/InputOutputInteraction.php index 44f84b6..16f34a3 100644 --- a/src/Companienv/IO/InputOutputInteraction.php +++ b/src/Companienv/IO/InputOutputInteraction.php @@ -27,7 +27,7 @@ public function ask(string $question, string $default = null) : string { $answer = (new QuestionHelper())->ask($this->input, $this->output, new Question($question, $default)); - if (!$answer) { + if (null === $answer || ('' === $answer && $default !== null)) { return $this->ask($question, $default); }