/** * * @param string $question * @param bool $default * * @return Boolean */ public function askConfirmation($question, $default = true) { $lines = array(); $lines[] = '<question>' . str_repeat(' ', $this->getBlockWidth()) . "</question>"; foreach (explode("\n", wordwrap($question, $this->getBlockWidth() - 4, "\n", true)) as $line) { $lines[] = '<question> ' . str_pad($line, $this->getBlockWidth() - 2) . '</question>'; } $lines[] = '<question>' . str_repeat(' ', $this->getBlockWidth() - 8) . '</question> <value>' . ($default ? '[Y/n]' : '[y/N]') . '</value> '; $formattedQuestion = implode("\n", $lines) . "\n"; return $this->prompter->askConfirmation($formattedQuestion, $default); }
/** * @test */ function it_can_ask_a_question_and_return_the_result() { $this->questionHelper->expects($this->once())->method('ask')->with($this->identicalTo($this->input), $this->identicalTo($this->output), $this->equalTo(new ConfirmationQuestion('Are you sure?', true)))->willReturn(true); $result = $this->prompter->askConfirmation('Are you sure?'); $this->assertEquals(true, $result); }