ConfirmTest.php 1.7 KB

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