SpinnerTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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(1000000);
  10. }
  11. /**
  12. * @doesNotPerformAssertions
  13. */
  14. public function testBasic()
  15. {
  16. $this->shouldWrite("\e[m[-=---]\e[0m");
  17. $this->shouldWrite("\e[m\e[1A\r\e[K[--=--]\e[0m");
  18. $this->shouldWrite("\e[m\e[1A\r\e[K[---=-]\e[0m");
  19. $spinner = $this->cli->spinner();
  20. $spinner->advance();
  21. $this->wait();
  22. $spinner->advance();
  23. $this->wait();
  24. $spinner->advance();
  25. }
  26. /**
  27. * @doesNotPerformAssertions
  28. */
  29. public function testQuick()
  30. {
  31. $this->shouldWrite("\e[m[-=---]\e[0m");
  32. $spinner = $this->cli->spinner();
  33. $spinner->advance();
  34. $spinner->advance();
  35. }
  36. /**
  37. * @doesNotPerformAssertions
  38. */
  39. public function testWithLabels()
  40. {
  41. $this->shouldWrite("\e[m[-=---] one\e[0m");
  42. $this->shouldWrite("\e[m\e[1A\r\e[K[--=--] two\e[0m");
  43. $this->shouldWrite("\e[m\e[1A\r\e[K[---=-] three\e[0m");
  44. $spinner = $this->cli->spinner();
  45. $spinner->advance("one");
  46. $this->wait();
  47. $spinner->advance("two");
  48. $this->wait();
  49. $spinner->advance("three");
  50. }
  51. /**
  52. * @doesNotPerformAssertions
  53. */
  54. public function testWithOptionalLabels()
  55. {
  56. $this->shouldWrite("\e[m[-=---] one\e[0m");
  57. $this->shouldWrite("\e[m\e[1A\r\e[K[--=--]\e[0m");
  58. $this->shouldWrite("\e[m\e[1A\r\e[K[---=-] three\e[0m");
  59. $spinner = $this->cli->spinner();
  60. $spinner->advance("one");
  61. $this->wait();
  62. $spinner->advance();
  63. $this->wait();
  64. $spinner->advance("three");
  65. }
  66. }