Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to type falsy answers #9

Merged
merged 2 commits into from
Feb 6, 2018
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"bin/companienv"
],
"require-dev": {
"behat/behat": "^3.4"
"behat/behat": "^3.4",
"phpspec/phpspec": "^4.3"
}
}
27 changes: 27 additions & 0 deletions spec/Companienv/IO/InputOutputInteractionSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace spec\Companienv\IO;

use Companienv\IO\InputOutputInteraction;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class InputOutputInteractionSpec extends ObjectBehavior
{
function let(InputInterface $input, OutputInterface $output)
{
$this->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');
}
}
2 changes: 1 addition & 1 deletion src/Companienv/IO/InputOutputInteraction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down