/**
  * Returns or initializes the symfony/console DialogHelper
  *
  * @return DialogHelper
  */
 protected function getDialogHelper()
 {
     if ($this->dialogHelper === NULL) {
         $this->dialogHelper = new DialogHelper();
         $helperSet = new HelperSet(array(new FormatterHelper()));
         $this->dialogHelper->setHelperSet($helperSet);
     }
     return $this->dialogHelper;
 }
 /**
  * Returns or initializes the symfony/console DialogHelper
  *
  * @return DialogHelper
  */
 protected function getDialogHelper()
 {
     if ($this->dialogHelper === null) {
         $this->dialogHelper = new DialogHelper();
         $helperSet = new HelperSet([new FormatterHelper()]);
         $this->dialogHelper->setHelperSet($helperSet);
     }
     return $this->dialogHelper;
 }
Esempio n. 3
0
 public function testAskAndValidate()
 {
     $dialog = new DialogHelper();
     $helperSet = new HelperSet(array(new FormatterHelper()));
     $dialog->setHelperSet($helperSet);
     $question = 'What color was the white horse of Henry IV?';
     $error = 'This is not a color!';
     $validator = function ($color) use($error) {
         if (!in_array($color, array('white', 'black'))) {
             throw new \InvalidArgumentException($error);
         }
         return $color;
     };
     $dialog->setInputStream($this->getInputStream("\nblack\n"));
     $this->assertEquals('white', $dialog->askAndValidate($this->getOutputStream(), $question, $validator, 2, 'white'));
     $this->assertEquals('black', $dialog->askAndValidate($this->getOutputStream(), $question, $validator, 2, 'white'));
     $dialog->setInputStream($this->getInputStream("green\nyellow\norange\n"));
     try {
         $this->assertEquals('white', $dialog->askAndValidate($this->getOutputStream(), $question, $validator, 2, 'white'));
         $this->fail();
     } catch (\InvalidArgumentException $e) {
         $this->assertEquals($error, $e->getMessage());
     }
 }