ConfirmTest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. /** @test */
  26. public function it_will_only_allow_strict_confirmations()
  27. {
  28. $this->shouldReadAndReturn('Y');
  29. $this->shouldReadAndReturn('y');
  30. $this->shouldReceiveSameLine();
  31. $this->shouldWrite("\e[mKeep going? [y/n] \e[0m", 2);
  32. $input = $this->cli->confirm('Keep going?', $this->reader);
  33. $input->confirmed();
  34. }
  35. }