Esempio n. 1
0
 /**
  * @param $question
  * @param ConsoleAdapter $console
  *
  * @return string|null
  */
 private function askNumberQuestion($question, ConsoleAdapter $console)
 {
     $console->writeLine($question . ' ([0-9]+)', ColorInterface::CYAN);
     $prompt = new Number('');
     $prompt->setConsole($console);
     $result = $prompt->show();
     return is_numeric($result) ? $result : null;
 }
Esempio n. 2
0
 public function testCanDefineAMax()
 {
     fwrite($this->adapter->stream, "1" . PHP_EOL);
     fwrite($this->adapter->stream, "11" . PHP_EOL);
     fwrite($this->adapter->stream, "6" . PHP_EOL);
     rewind($this->adapter->stream);
     $this->adapter->autoRewind = false;
     $number = new Number('Give me a number', false, false, 5, 10);
     $number->setConsole($this->adapter);
     ob_start();
     $response = $number->show();
     $text = ob_get_clean();
     $this->assertTrue((bool) preg_match('#Please enter a number not smaller than 5#', $text));
     $this->assertTrue((bool) preg_match('#Please enter a number not greater than 10#', $text));
     $this->assertEquals('6', $response);
 }