RadioTest.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. // Select the first one
  19. $this->shouldReadCharAndReturn(' ');
  20. // Go down one
  21. $this->shouldReadCharAndReturn("\e");
  22. $this->shouldReadCharAndReturn("[B", 2);
  23. // Go down one
  24. $this->shouldReadCharAndReturn("\e");
  25. $this->shouldReadCharAndReturn("[B", 2);
  26. // Select the third one
  27. $this->shouldReadCharAndReturn(' ');
  28. // Confirm entry
  29. $this->shouldReadCharAndReturn("\n");
  30. $this->shouldWrite("\e[mCurrent mood: (use <space> to select)\e[0m");
  31. $this->shouldWrite("\e[m❯ ○ Happy" . str_repeat(' ', 71) . "\e[0m");
  32. $this->shouldWrite("\e[m ○ Sad" . str_repeat(' ', 73) . "\e[0m");
  33. $this->shouldReceiveSameLine();
  34. $this->shouldWrite("\e[m ○ Thrilled" . str_repeat(' ', 68) . "\e[10D\e[8m\e[0m");
  35. $this->util->system->shouldReceive('exec')->with('stty -icanon');
  36. $this->util->system->shouldReceive('exec')->with('stty sane');
  37. $this->shouldHideCursor();
  38. $this->shouldReceiveSameLine();
  39. $this->shouldWrite("\e[2A\r", 4);
  40. $this->shouldWrite("\e[m❯ ● Happy" . str_repeat(' ', 71) . "\e[0m");
  41. $this->shouldWrite("\e[m ○ Sad" . str_repeat(' ', 73) . "\e[0m", 3);
  42. $this->shouldReceiveSameLine();
  43. $this->shouldWrite("\e[m ○ Thrilled" . str_repeat(' ', 68) . "\e[10D\e[8m\e[0m", 2);
  44. $this->shouldWrite("\e[m ● Happy" . str_repeat(' ', 71) . "\e[0m", 2);
  45. $this->shouldWrite("\e[m❯ ○ Sad" . str_repeat(' ', 73) . "\e[0m");
  46. $this->shouldReceiveSameLine();
  47. $this->shouldReceiveSameLine();
  48. $this->shouldWrite("\e[m❯ ○ Thrilled" . str_repeat(' ', 68) . "\e[10D\e[8m\e[0m");
  49. $this->shouldReceiveSameLine();
  50. $this->shouldWrite("\e[m ○ Happy" . str_repeat(' ', 71) . "\e[0m");
  51. $this->shouldWrite("\e[m❯ ● Thrilled" . str_repeat(' ', 68) . "\e[10D\e[8m\e[0m");
  52. $this->shouldShowCursor();
  53. $this->shouldReceiveSameLine();
  54. $this->shouldWrite("\e[0m");
  55. $options = ['Happy', 'Sad', 'Thrilled'];
  56. $input = $this->cli->radio('Current mood:', $options, $this->reader);
  57. $response = $input->prompt();
  58. $this->assertSame('Thrilled', $response);
  59. }
  60. }