AnimationTest.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <?php
  2. namespace League\CLImate\Tests\Animation;
  3. use League\CLImate\Tests\TestBase;
  4. use Mockery;
  5. class AnimationTest extends TestBase
  6. {
  7. use ExitToTopFrames, ExitToBottomFrames, ExitToLeftFrames, ExitToRightFrames, RunFrames;
  8. private function addArt(): void
  9. {
  10. $this->cli->addArt(__DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'art');
  11. }
  12. protected function emptyFrame()
  13. {
  14. $this->shouldWrite("\e[m\e[0m")->ordered();
  15. $this->shouldWrite("\e[m\e[0m")->ordered();
  16. $this->shouldWrite("\e[m\e[0m")->ordered();
  17. $this->shouldWrite("\e[m\e[0m")->ordered();
  18. $this->shouldWrite("\e[m\e[0m")->ordered();
  19. $this->shouldWrite("\e[m\e[0m")->ordered();
  20. }
  21. protected function blankLines($count = 1)
  22. {
  23. for ($i = 1; $i <= $count; $i++) {
  24. $this->shouldWrite("\e[m\r\e[K\e[0m")->ordered();
  25. }
  26. }
  27. protected function getSleeper($count)
  28. {
  29. $sleeper = Mockery::mock('League\CLImate\TerminalObject\Helper\Sleeper');
  30. $sleeper->shouldReceive('sleep')->times($count);
  31. return $sleeper;
  32. }
  33. protected function runAsc($base, $end)
  34. {
  35. for ($i = 1; $i <= $end; $i++) {
  36. $this->{$base . $i}();
  37. }
  38. }
  39. protected function runDesc($base, $end)
  40. {
  41. for ($i = $end; $i >= 1; $i--) {
  42. $this->{$base . $i}();
  43. }
  44. }
  45. protected function assertScrolledRight()
  46. {
  47. $this->assertEnteredFromLeft();
  48. $this->assertExitedRight();
  49. }
  50. protected function assertEnteredFromLeft()
  51. {
  52. $this->emptyFrame();
  53. $this->runDesc('exitLeftFrame', 8);
  54. $this->fullArtExitLeftPlus();
  55. }
  56. protected function assertEnteredFromRight()
  57. {
  58. $this->runDesc('exitRightFrameEnd', 8);
  59. for ($i = 71; $i >= 0; $i--) {
  60. $this->exitRightFrame($i);
  61. }
  62. }
  63. protected function assertExitedLeft()
  64. {
  65. $this->runAsc('exitLeftFrame', 8);
  66. }
  67. protected function assertExitedRight()
  68. {
  69. for ($i = 0; $i <= 71; $i++) {
  70. $this->exitRightFrame($i);
  71. }
  72. $this->runAsc('exitRightFrameEnd', 9);
  73. }
  74. /**
  75. * @test
  76. * @doesNotPerformAssertions
  77. */
  78. public function it_can_exit_to_top()
  79. {
  80. $this->fullArtExitTop();
  81. $this->fullArtExitTopPlus(3);
  82. $this->runAsc('exitTopFrame', 6);
  83. $this->exitTopFrame6();
  84. $this->cli->animation('404', $this->getSleeper(11))->exitTo('top');
  85. }
  86. /**
  87. * @test
  88. * @doesNotPerformAssertions
  89. */
  90. public function it_can_enter_from_top()
  91. {
  92. $this->emptyFrame();
  93. $this->runDesc('exitTopFrame', 6);
  94. $this->fullArtExitTopPlus(4);
  95. $this->cli->animation('404', $this->getSleeper(11))->enterFrom('top');
  96. }
  97. /**
  98. * @test
  99. * @doesNotPerformAssertions
  100. */
  101. public function it_can_exit_to_bottom()
  102. {
  103. $this->fullArtExitBottom();
  104. $this->fullArtExitBottomPlus(3);
  105. $this->runAsc('exitBottomFrame', 6);
  106. $this->exitBottomFrame6();
  107. $this->cli->animation('404', $this->getSleeper(11))->exitTo('bottom');
  108. }
  109. /**
  110. * @test
  111. * @doesNotPerformAssertions
  112. */
  113. public function it_can_enter_from_bottom()
  114. {
  115. $this->emptyFrame();
  116. $this->runDesc('exitBottomFrame', 6);
  117. $this->fullArtExitBottomPlus(4);
  118. $this->cli->animation('404', $this->getSleeper(11))->enterFrom('bottom');
  119. }
  120. /**
  121. * @test
  122. * @doesNotPerformAssertions
  123. */
  124. public function it_can_exit_to_left()
  125. {
  126. $this->fullArtExitLeft();
  127. $this->fullArtExitLeftPlus(4);
  128. $this->assertExitedLeft();
  129. $this->exitLeftFrame9();
  130. $this->addArt();
  131. $this->cli->animation('4', $this->getSleeper(14))->exitTo('left');
  132. }
  133. /**
  134. * @test
  135. * @doesNotPerformAssertions
  136. */
  137. public function it_can_enter_from_left()
  138. {
  139. $this->assertEnteredFromLeft();
  140. $this->fullArtExitLeftPlus(4);
  141. $this->addArt();
  142. $this->cli->animation('4', $this->getSleeper(14))->enterFrom('left');
  143. }
  144. /**
  145. * @test
  146. * @doesNotPerformAssertions
  147. */
  148. public function it_can_exit_to_right()
  149. {
  150. $this->fullArtExitRight();
  151. $this->exitRightFrame(0, 3);
  152. $this->assertExitedRight();
  153. $this->addArt();
  154. $this->cli->animation('4', $this->getSleeper(85))->exitTo('right');
  155. }
  156. /**
  157. * @test
  158. * @doesNotPerformAssertions
  159. */
  160. public function it_can_enter_from_right()
  161. {
  162. $this->enterRightFrame1();
  163. $this->assertEnteredFromRight();
  164. $this->exitRightFrame(0, 4);
  165. $this->addArt();
  166. $this->cli->animation('4', $this->getSleeper(85))->enterFrom('right');
  167. }
  168. /**
  169. * @test
  170. * @doesNotPerformAssertions
  171. */
  172. public function it_will_scroll_to_the_right_by_default()
  173. {
  174. $this->assertScrolledRight();
  175. $this->addArt();
  176. $this->cli->animation('4', $this->getSleeper(91))->scroll();
  177. }
  178. /**
  179. * @test
  180. * @doesNotPerformAssertions
  181. */
  182. public function it_can_scroll_to_the_right()
  183. {
  184. $this->assertScrolledRight();
  185. $this->addArt();
  186. $this->cli->animation('4', $this->getSleeper(91))->scroll('right');
  187. }
  188. /**
  189. * @test
  190. * @doesNotPerformAssertions
  191. */
  192. public function it_can_scroll_to_the_left()
  193. {
  194. $this->emptyFrame();
  195. $this->assertEnteredFromRight();
  196. $this->fullArtExitLeftPlus();
  197. $this->assertExitedLeft();
  198. $this->exitRightFrameEnd9();
  199. $this->addArt();
  200. $this->cli->animation('4', $this->getSleeper(91))->scroll('left');
  201. }
  202. /**
  203. * @test
  204. * @doesNotPerformAssertions
  205. */
  206. public function it_can_scroll_up()
  207. {
  208. $this->emptyFrame();
  209. $this->runDesc('exitBottomFrame', 5);
  210. $this->fullArtExitBottomPlus();
  211. $this->runAsc('exitTopFrame', 6);
  212. $this->cli->animation('404', $this->getSleeper(13))->scroll('up');
  213. }
  214. /**
  215. * @test
  216. * @doesNotPerformAssertions
  217. */
  218. public function it_can_scroll_down()
  219. {
  220. $this->emptyFrame();
  221. $this->runDesc('exitTopFrame', 5);
  222. $this->fullArtExitBottomPlus();
  223. $this->runAsc('exitBottomFrame', 6);
  224. $this->cli->animation('404', $this->getSleeper(13))->scroll('down');
  225. }
  226. /**
  227. * @test
  228. * @doesNotPerformAssertions
  229. */
  230. public function it_can_run_a_directory_animation()
  231. {
  232. $this->runAsc('runFrames', 5);
  233. $this->addArt();
  234. $this->cli->animation('work-it', $this->getSleeper(5))->run();
  235. }
  236. /**
  237. * @test
  238. * @doesNotPerformAssertions
  239. */
  240. public function it_404s_when_it_gets_invalid_art()
  241. {
  242. $this->emptyFrame();
  243. $this->runDesc('exitBottomFrame', 6);
  244. $this->fullArtExitBottomPlus(4);
  245. $this->cli->animation('does-not-exist', $this->getSleeper(11))->enterFrom('bottom');
  246. }
  247. }