SpinnerTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace League\CLImate\Tests\TerminalObject\Dynamic;
  3. use League\CLImate\Tests\TestBase;
  4. use function usleep;
  5. class SpinnerTest extends TestBase
  6. {
  7. private function wait()
  8. {
  9. usleep(100000);
  10. }
  11. public function testBasic()
  12. {
  13. $this->shouldWrite("\e[m[-=---]\e[0m");
  14. $this->shouldWrite("\e[m\e[1A\r\e[K[--=--]\e[0m");
  15. $this->shouldWrite("\e[m\e[1A\r\e[K[---=-]\e[0m");
  16. $spinner = $this->cli->spinner();
  17. $spinner->advance();
  18. $this->wait();
  19. $spinner->advance();
  20. $this->wait();
  21. $spinner->advance();
  22. }
  23. public function testQuick()
  24. {
  25. $this->shouldWrite("\e[m[-=---]\e[0m");
  26. $spinner = $this->cli->spinner();
  27. $spinner->advance();
  28. $spinner->advance();
  29. }
  30. public function testWithLabels()
  31. {
  32. $this->shouldWrite("\e[m[-=---] one\e[0m");
  33. $this->shouldWrite("\e[m\e[1A\r\e[K[--=--] two\e[0m");
  34. $this->shouldWrite("\e[m\e[1A\r\e[K[---=-] three\e[0m");
  35. $spinner = $this->cli->spinner();
  36. $spinner->advance("one");
  37. $this->wait();
  38. $spinner->advance("two");
  39. $this->wait();
  40. $spinner->advance("three");
  41. }
  42. public function testWithOptionalLabels()
  43. {
  44. $this->shouldWrite("\e[m[-=---] one\e[0m");
  45. $this->shouldWrite("\e[m\e[1A\r\e[K[--=--]\e[0m");
  46. $this->shouldWrite("\e[m\e[1A\r\e[K[---=-] three\e[0m");
  47. $spinner = $this->cli->spinner();
  48. $spinner->advance("one");
  49. $this->wait();
  50. $spinner->advance();
  51. $this->wait();
  52. $spinner->advance("three");
  53. }
  54. }