askAndValidate() public method

public askAndValidate ( $question, callable $validator, $attempts = false, $default = null )
$validator callable
Ejemplo n.º 1
0
 public function testAskAndValidate()
 {
     $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('askAndValidate')->with($this->isInstanceOf('Symfony\\Component\\Console\\Output\\OutputInterface'), $this->equalTo('Is valid?'), $this->callback(function ($validator) {
         return 'validator' === $validator();
     }), $this->equalTo(10), $this->equalTo('default'));
     $helperMock->expects($this->once())->method('get')->with($this->equalTo('dialog'))->will($this->returnValue($dialogMock));
     $consoleIO = new ConsoleIO($inputMock, $outputMock, $helperMock);
     $consoleIO->askAndValidate('Is valid?', function () {
         return 'validator';
     }, 10, 'default');
 }
Ejemplo n.º 2
0
 public function testAskAndValidate()
 {
     $inputMock = $this->getMockBuilder('Symfony\\Component\\Console\\Input\\InputInterface')->getMock();
     $outputMock = $this->getMockBuilder('Symfony\\Component\\Console\\Output\\OutputInterface')->getMock();
     $questionHelperMock = $this->getMockBuilder('Symfony\\Component\\Console\\Helper\\QuestionHelper')->getMock();
     $helperMock = $this->getMockBuilder('Symfony\\Component\\Console\\Helper\\HelperSet')->getMock();
     $question = new \Symfony\Component\Console\Question\Question('Is valid?', true);
     $question->setMaxAttempts(10);
     $question->setValidator(function ($answer) {
         return $answer;
     });
     $questionHelperMock->expects($this->once())->method('ask')->with($this->isInstanceOf('Symfony\\Component\\Console\\Input\\InputInterface'), $this->isInstanceOf('Symfony\\Component\\Console\\Output\\OutputInterface'), $question);
     $helperMock->expects($this->once())->method('get')->with($this->equalTo('question'))->will($this->returnValue($questionHelperMock));
     $consoleIO = new ConsoleIO($inputMock, $outputMock, $helperMock);
     $consoleIO->askAndValidate('Is valid?', function ($answer) {
         return $answer;
     }, 10, true);
 }
Ejemplo n.º 3
0
 public function testAskAndValidate()
 {
     $this->command->setCode(function (InputInterface $input, OutputInterface $output) use(&$isDecorated) {
         $io = new ConsoleIO($input, $output);
         $result = $io->askAndValidate('what is your name?', function ($value) {
             return $value === 'Yo! Symfony';
         }, false, 'Yo! Symfony');
         $this->assertEquals('Yo! Symfony', $result);
     });
     $this->tester->execute([], ['interactive' => false, 'decorated' => false]);
 }