123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- <?php
- namespace League\CLImate\Tests;
- use Mockery;
- class AnimationTest extends TestBase
- {
- use ExitToTopFrames, ExitToBottomFrames, ExitToLeftFrames, ExitToRightFrames, RunFrames;
- protected function emptyFrame()
- {
- $this->shouldWrite("\e[m\e[0m")->ordered();
- $this->shouldWrite("\e[m\e[0m")->ordered();
- $this->shouldWrite("\e[m\e[0m")->ordered();
- $this->shouldWrite("\e[m\e[0m")->ordered();
- $this->shouldWrite("\e[m\e[0m")->ordered();
- $this->shouldWrite("\e[m\e[0m")->ordered();
- }
- protected function blankLines($count = 1)
- {
- for ($i = 1; $i <= $count; $i++) {
- $this->shouldWrite("\e[m\r\e[K\e[0m")->ordered();
- }
- }
- protected function getSleeper($count)
- {
- $sleeper = Mockery::mock('League\CLImate\TerminalObject\Helper\Sleeper');
- $sleeper->shouldReceive('sleep')->times($count);
- return $sleeper;
- }
- protected function runAsc($base, $end)
- {
- for ($i = 1; $i <= $end; $i++) {
- $this->{$base . $i}();
- }
- }
- protected function runDesc($base, $end)
- {
- for ($i = $end; $i >= 1; $i--) {
- $this->{$base . $i}();
- }
- }
- protected function assertScrolledRight()
- {
- $this->assertEnteredFromLeft();
- $this->assertExitedRight();
- }
- protected function assertEnteredFromLeft()
- {
- $this->emptyFrame();
- $this->runDesc('exitLeftFrame', 8);
- $this->fullArtExitLeftPlus();
- }
- protected function assertEnteredFromRight()
- {
- $this->runDesc('exitRightFrameEnd', 8);
- for ($i = 71; $i >= 0; $i--) {
- $this->exitRightFrame($i);
- }
- }
- protected function assertExitedLeft()
- {
- $this->runAsc('exitLeftFrame', 8);
- }
- protected function assertExitedRight()
- {
- for ($i = 0; $i <= 71; $i++) {
- $this->exitRightFrame($i);
- }
- $this->runAsc('exitRightFrameEnd', 9);
- }
- /** @test */
- public function it_can_exit_to_top()
- {
- $this->fullArtExitTop();
- $this->fullArtExitTopPlus(3);
- $this->runAsc('exitTopFrame', 6);
- $this->exitTopFrame6();
- $this->cli->animation('404', $this->getSleeper(11))->exitTo('top');
- }
- /** @test */
- public function it_can_enter_from_top()
- {
- $this->emptyFrame();
- $this->runDesc('exitTopFrame', 6);
- $this->fullArtExitTopPlus(4);
- $this->cli->animation('404', $this->getSleeper(11))->enterFrom('top');
- }
- /** @test */
- public function it_can_exit_to_bottom()
- {
- $this->fullArtExitBottom();
- $this->fullArtExitBottomPlus(3);
- $this->runAsc('exitBottomFrame', 6);
- $this->exitBottomFrame6();
- $this->cli->animation('404', $this->getSleeper(11))->exitTo('bottom');
- }
- /** @test */
- public function it_can_enter_from_bottom()
- {
- $this->emptyFrame();
- $this->runDesc('exitBottomFrame', 6);
- $this->fullArtExitBottomPlus(4);
- $this->cli->animation('404', $this->getSleeper(11))->enterFrom('bottom');
- }
- /** @test */
- public function it_can_exit_to_left()
- {
- $this->fullArtExitLeft();
- $this->fullArtExitLeftPlus(4);
- $this->assertExitedLeft();
- $this->exitLeftFrame9();
- $this->cli->addArt(__DIR__ . '/art');
- $this->cli->animation('4', $this->getSleeper(14))->exitTo('left');
- }
- /** @test */
- public function it_can_enter_from_left()
- {
- $this->assertEnteredFromLeft();
- $this->fullArtExitLeftPlus(4);
- $this->cli->addArt(__DIR__ . '/art');
- $this->cli->animation('4', $this->getSleeper(14))->enterFrom('left');
- }
- /** @test */
- public function it_can_exit_to_right()
- {
- $this->fullArtExitRight();
- $this->exitRightFrame(0, 3);
- $this->assertExitedRight();
- $this->cli->addArt(__DIR__ . '/art');
- $this->cli->animation('4', $this->getSleeper(85))->exitTo('right');
- }
- /** @test */
- public function it_can_enter_from_right()
- {
- $this->enterRightFrame1();
- $this->assertEnteredFromRight();
- $this->exitRightFrame(0, 4);
- $this->cli->addArt(__DIR__ . '/art');
- $this->cli->animation('4', $this->getSleeper(85))->enterFrom('right');
- }
- /** @test */
- public function it_will_scroll_to_the_right_by_default()
- {
- $this->assertScrolledRight();
- $this->cli->addArt(__DIR__ . '/art');
- $this->cli->animation('4', $this->getSleeper(91))->scroll();
- }
- /** @test */
- public function it_can_scroll_to_the_right()
- {
- $this->assertScrolledRight();
- $this->cli->addArt(__DIR__ . '/art');
- $this->cli->animation('4', $this->getSleeper(91))->scroll('right');
- }
- /** @test */
- public function it_can_scroll_to_the_left()
- {
- $this->emptyFrame();
- $this->assertEnteredFromRight();
- $this->fullArtExitLeftPlus();
- $this->assertExitedLeft();
- $this->exitRightFrameEnd9();
- $this->cli->addArt(__DIR__ . '/art');
- $this->cli->animation('4', $this->getSleeper(91))->scroll('left');
- }
- /** @test */
- public function it_can_scroll_up()
- {
- $this->emptyFrame();
- $this->runDesc('exitBottomFrame', 5);
- $this->fullArtExitBottomPlus();
- $this->runAsc('exitTopFrame', 6);
- $this->cli->animation('404', $this->getSleeper(13))->scroll('up');
- }
- /** @test */
- public function it_can_scroll_down()
- {
- $this->emptyFrame();
- $this->runDesc('exitTopFrame', 5);
- $this->fullArtExitBottomPlus();
- $this->runAsc('exitBottomFrame', 6);
- $this->cli->animation('404', $this->getSleeper(13))->scroll('down');
- }
- /** @test */
- public function it_can_run_a_directory_animation()
- {
- $this->runAsc('runFrames', 5);
- $this->cli->addArt(__DIR__ . '/art');
- $this->cli->animation('work-it', $this->getSleeper(5))->run();
- }
- /** @test */
- public function it_404s_when_it_gets_invalid_art()
- {
- $this->emptyFrame();
- $this->runDesc('exitBottomFrame', 6);
- $this->fullArtExitBottomPlus(4);
- $this->cli->animation('does-not-exist', $this->getSleeper(11))->enterFrom('bottom');
- }
- }
|