RadioTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace League\CLImate\Tests;
  3. class RadioTest extends TestBase
  4. {
  5. protected function shouldHideCursor()
  6. {
  7. $this->shouldReceiveSameLine();
  8. $this->shouldWrite("\e[?25l");
  9. }
  10. protected function shouldShowCursor()
  11. {
  12. $this->shouldReceiveSameLine();
  13. $this->shouldWrite("\e[?25h");
  14. }
  15. /** @test */
  16. public function it_will_select_only_one_item()
  17. {
  18. // Go down one
  19. $this->shouldReadCharAndReturn("\e");
  20. $this->shouldReadCharAndReturn("[B", 2);
  21. // Go down one
  22. $this->shouldReadCharAndReturn("\e");
  23. $this->shouldReadCharAndReturn("[B", 2);
  24. // Confirm entry
  25. $this->shouldReadCharAndReturn("\n");
  26. $this->shouldWrite("\e[mCurrent mood: (press <Enter> to select)\e[0m");
  27. $this->shouldWrite("\e[m❯ ○ Happy" . str_repeat(' ', 71) . "\e[0m");
  28. $this->shouldWrite("\e[m ○ Sad" . str_repeat(' ', 73) . "\e[0m");
  29. $this->shouldReceiveSameLine();
  30. $this->shouldWrite("\e[m ○ Thrilled" . str_repeat(' ', 68) . "\e[10D\e[8m\e[0m");
  31. $this->util->system->shouldReceive('exec')->with('stty -icanon');
  32. $this->util->system->shouldReceive('exec')->with('stty sane');
  33. $this->shouldHideCursor();
  34. $this->shouldReceiveSameLine();
  35. $this->shouldWrite("\e[2A\r", 2);
  36. $this->shouldReceiveSameLine();
  37. $this->shouldWrite("\e[m ○ Happy" . str_repeat(' ', 71) . "\e[0m", 2);
  38. $this->shouldWrite("\e[m❯ ○ Sad" . str_repeat(' ', 73) . "\e[0m");
  39. $this->shouldWrite("\e[m ○ Thrilled" . str_repeat(' ', 68) . "\e[10D\e[8m\e[0m");
  40. $this->shouldReceiveSameLine();
  41. $this->shouldWrite("\e[m ○ Sad" . str_repeat(' ', 73) . "\e[0m");
  42. $this->shouldWrite("\e[m❯ ○ Thrilled" . str_repeat(' ', 68) . "\e[10D\e[8m\e[0m");
  43. $this->shouldShowCursor();
  44. $this->shouldReceiveSameLine();
  45. $this->shouldWrite("\e[0m");
  46. $options = ['Happy', 'Sad', 'Thrilled'];
  47. $input = $this->cli->radio('Current mood:', $options, $this->reader);
  48. $response = $input->prompt();
  49. $this->assertSame('Thrilled', $response);
  50. }
  51. }