/** * */ public function testRead() { $reader = $this->getReader(); $reader->shouldReceive('read')->once()->andReturn('user input'); $arguments = []; $input = new Input($reader, $arguments); $this->assertSame('user input', $input->read()); }
/** * Writes question to output and returns hidden user input. * * @access public * @param string $question Question to ask * @param null|mixed $default Default if no input is entered * @param boolean $fallback Fall back to non-hidden input? * @return string */ public function ask($question, $default = null, $fallback = false) { if (DIRECTORY_SEPARATOR === '\\' || $this->hasStty()) { $this->output->write(trim($question) . ' '); if (DIRECTORY_SEPARATOR === '\\') { $answer = trim(shell_exec(__DIR__ . '/resources/hiddeninput.exe')); } else { $settings = shell_exec('stty -g'); exec('stty -echo'); $answer = $this->input->read(); exec('stty ' . $settings); } $this->output->write(PHP_EOL); return empty($answer) ? $default : $answer; } elseif ($fallback) { return parent::ask($question, $default); } else { throw new RuntimeException(vsprintf("%s(): Unable to hide the user input.", [__METHOD__])); } }
/** * Writes question to output and returns user input. * * @access public * @param string $question Question to ask * @param null|mixed $default Default if no input is entered * @return string */ public function ask($question, $default = null) { $this->output->write(trim($question) . ' '); $answer = $this->input->read(); return empty($answer) ? $default : $answer; }