RadioTest.php 2.2 KB

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