Skip to content

Commit ec0f31c

Browse files
committed
Allow to type falsy answers
1 parent dad3f0c commit ec0f31c

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"bin/companienv"
3636
],
3737
"require-dev": {
38-
"behat/behat": "^3.4"
38+
"behat/behat": "^3.4",
39+
"phpspec/phpspec": "^4.3"
3940
}
4041
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace spec\Companienv\IO;
4+
5+
use Companienv\IO\InputOutputInteraction;
6+
use PhpSpec\ObjectBehavior;
7+
use Prophecy\Argument;
8+
use Symfony\Component\Console\Input\InputInterface;
9+
use Symfony\Component\Console\Output\OutputInterface;
10+
11+
class InputOutputInteractionSpec extends ObjectBehavior
12+
{
13+
function let(InputInterface $input, OutputInterface $output)
14+
{
15+
$this->beConstructedWith($input, $output);
16+
}
17+
18+
function it_will_return_the_default_value()
19+
{
20+
$this->ask('VALUE ?', 'true')->shouldReturn('true');
21+
}
22+
23+
function it_will_return_the_default_value_even_if_it_looks_falsy()
24+
{
25+
$this->ask('COUNT ?', '0')->shouldReturn('0');
26+
}
27+
}

src/Companienv/IO/InputOutputInteraction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function ask(string $question, string $default = null) : string
2727
{
2828
$answer = (new QuestionHelper())->ask($this->input, $this->output, new Question($question, $default));
2929

30-
if (!$answer) {
30+
if (null === $answer || ('' === $answer && $default !== null)) {
3131
return $this->ask($question, $default);
3232
}
3333

0 commit comments

Comments
 (0)