ConfirmTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace League\CLImate\Tests\TerminalObject\Dynamic;
  3. use League\CLImate\Tests\TestBase;
  4. class ConfirmTest extends TestBase
  5. {
  6. /** @test */
  7. public function it_will_return_true_for_y()
  8. {
  9. $this->shouldReadAndReturn('y');
  10. $this->shouldReceiveSameLine();
  11. $this->shouldWrite("\e[mKeep going? [y/N] \e[0m");
  12. $input = $this->cli->confirm('Keep going?', $this->reader);
  13. $response = $input->confirmed();
  14. $this->assertTrue($response);
  15. }
  16. /** @test */
  17. public function it_will_return_false_for_n()
  18. {
  19. $this->shouldReadAndReturn('n');
  20. $this->shouldReceiveSameLine();
  21. $this->shouldWrite("\e[mKeep going? [y/N] \e[0m");
  22. $input = $this->cli->confirm('Keep going?', $this->reader);
  23. $response = $input->confirmed();
  24. $this->assertFalse($response);
  25. }
  26. /**
  27. * Ensure that the default (yes) is respected.
  28. */
  29. public function testDefaultToYes()
  30. {
  31. $this->shouldReadAndReturn("");
  32. $this->shouldReceiveSameLine();
  33. $this->shouldWrite("\e[mKeep going? [Y/n] \e[0m");
  34. $input = $this->cli->confirm("Keep going?", $this->reader);
  35. $input->defaultTo("y");
  36. $response = $input->confirmed();
  37. $this->assertTrue($response);
  38. }
  39. /**
  40. * Ensure that the default (no) is respected.
  41. */
  42. public function testDefaultToNo()
  43. {
  44. $this->shouldReadAndReturn("");
  45. $this->shouldReceiveSameLine();
  46. $this->shouldWrite("\e[mKeep going? [y/N] \e[0m");
  47. $input = $this->cli->confirm("Keep going?", $this->reader);
  48. $input->defaultTo("n");
  49. $response = $input->confirmed();
  50. $this->assertFalse($response);
  51. }
  52. }