Merge remote-tracking branch 'fduch/console-select-support'
commit
d24ea66892
|
@ -279,4 +279,12 @@ class ConsoleIO extends BaseIO
|
|||
|
||||
return \Seld\CliPrompt\CliPrompt::hiddenPrompt(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function select($question, $choices, $default = null, $attempts = false, $errorMessage = 'Value "%s" is invalid', $multiselect = false)
|
||||
{
|
||||
return $this->helperSet->get('dialog')->select($this->output, $question, $choices, $default, $attempts, $errorMessage, $multiselect);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,6 +149,22 @@ interface IOInterface
|
|||
*/
|
||||
public function askAndHideAnswer($question);
|
||||
|
||||
/**
|
||||
* Asks the user to select a value.
|
||||
*
|
||||
* @param string|array $question The question to ask
|
||||
* @param array $choices List of choices to pick from
|
||||
* @param bool|string $default The default answer if the user enters nothing
|
||||
* @param bool|int $attempts Max number of times to ask before giving up (false by default, which means infinite)
|
||||
* @param string $errorMessage Message which will be shown if invalid value from choice list would be picked
|
||||
* @param bool $multiselect Select more than one value separated by comma
|
||||
*
|
||||
* @return int|string|array The selected value or values (the key of the choices array)
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function select($question, $choices, $default = null, $attempts = false, $errorMessage = 'Value "%s" is invalid', $multiselect = false);
|
||||
|
||||
/**
|
||||
* Get all authentication information entered.
|
||||
*
|
||||
|
|
|
@ -118,4 +118,12 @@ class NullIO extends BaseIO
|
|||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function select($question, $choices, $default = null, $attempts = false, $errorMessage = 'Value "%s" is invalid', $multiselect = false)
|
||||
{
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -222,6 +222,31 @@ class ConsoleIOTest extends TestCase
|
|||
$consoleIO->askAndValidate('Why?', 'validator', 10, 'default');
|
||||
}
|
||||
|
||||
public function testSelect()
|
||||
{
|
||||
$inputMock = $this->getMock('Symfony\Component\Console\Input\InputInterface');
|
||||
$outputMock = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
|
||||
$dialogMock = $this->getMock('Symfony\Component\Console\Helper\DialogHelper');
|
||||
$helperMock = $this->getMock('Symfony\Component\Console\Helper\HelperSet');
|
||||
|
||||
$dialogMock->expects($this->once())
|
||||
->method('select')
|
||||
->with($this->isInstanceOf('Symfony\Component\Console\Output\OutputInterface'),
|
||||
$this->equalTo('Select item'),
|
||||
$this->equalTo(array("item1", "item2")),
|
||||
$this->equalTo(null),
|
||||
$this->equalTo(false),
|
||||
$this->equalTo("Error message"),
|
||||
$this->equalTo(true));
|
||||
$helperMock->expects($this->once())
|
||||
->method('get')
|
||||
->with($this->equalTo('dialog'))
|
||||
->will($this->returnValue($dialogMock));
|
||||
|
||||
$consoleIO = new ConsoleIO($inputMock, $outputMock, $helperMock);
|
||||
$consoleIO->select('Select item', array("item1", "item2"), null, false, "Error message", true);
|
||||
}
|
||||
|
||||
public function testSetAndgetAuthentication()
|
||||
{
|
||||
$inputMock = $this->getMock('Symfony\Component\Console\Input\InputInterface');
|
||||
|
|
|
@ -67,4 +67,11 @@ class NullIOTest extends TestCase
|
|||
|
||||
$this->assertEquals('foo', $io->askAndValidate('question', 'validator', false, 'foo'));
|
||||
}
|
||||
|
||||
public function testSelect()
|
||||
{
|
||||
$io = new NullIO();
|
||||
|
||||
$this->assertEquals('1', $io->select('question', array('item1', 'item2'), '1', 2, 'foo', true));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue