TR
apps/winzik / tests / PlayerTest.php · commit 6576d6f
<?phpnamespace Tests;use App\Audio\Player;/** The player window of 2001: its buttons, sliders, counter, lyrics, play list. */final class PlayerTest extends PlayerTestCase{    public function testPlayStartsTheFirstSongAndTheCounterRuns(): void    {        $this->startPlayer();        self::assertSame(Player::STOPPED, $this->wz->player->state);        $this->clickControl($this->desk->main, 'play');        self::assertSame(Player::PLAYING, $this->wz->player->state);        self::assertStringEndsWith('winzik.mp3', (string)$this->wz->player->file);        $this->game->wait(3);        self::assertEqualsWithDelta(3.0, $this->wz->player->position, 0.1);        $this->game->shot('playing');    }    public function testTheLyricsFollowTheSong(): void    {        $this->startPlayer();        $this->clickControl($this->desk->main, 'play');        self::assertNotNull($this->wz->lyrics, 'winzik.lyr is next to winzik.mp3');        $this->wz->seek(16.5);        $this->game->run(2);        self::assertSame('Play, pause, stop et puis suivant', $this->wz->lyricLine());        $this->game->wait(4);        self::assertSame('La playlist défile lentement', $this->wz->lyricLine());        $this->game->shot('lyrics');    }    public function testASongWithoutLyricsSaysSo(): void    {        $this->startPlayer();        $this->wz->playIndex(1);        $this->game->run(2);        self::assertSame('Aucune Parole disponible', $this->wz->lyricLine());    }    public function testPauseThenPlayGoesOnFromTheSamePlace(): void    {        $this->startPlayer();        $this->clickControl($this->desk->main, 'play');        $this->game->wait(2);        $this->clickControl($this->desk->main, 'pause');        $at = $this->wz->player->position;        $this->game->wait(2);        self::assertSame(Player::PAUSED, $this->wz->player->state);        self::assertEqualsWithDelta($at, $this->wz->player->position, 0.001, 'paused: the counter waits');        $this->clickControl($this->desk->main, 'play');        $this->game->wait(1);        self::assertGreaterThan($at + 0.9, $this->wz->player->position);    }    public function testStopGoesBackToTheStart(): void    {        $this->startPlayer();        $this->clickControl($this->desk->main, 'play');        $this->game->wait(2);        $this->clickControl($this->desk->main, 'stop');        self::assertSame(Player::STOPPED, $this->wz->player->state);        self::assertSame(0.0, $this->wz->player->position);    }    public function testTheEndOfASongPlaysTheNextOne(): void    {        $this->startPlayer();        $this->clickControl($this->desk->main, 'play');        $this->wz->seek($this->wz->player->duration() - 0.5);        $this->game->wait(1.5);        self::assertSame(1, $this->wz->playlist->active);        self::assertSame(Player::PLAYING, $this->wz->player->state);        self::assertStringEndsWith('archettes-city.ogg', (string)$this->wz->player->file);    }    public function testNextAndPreviousButtonsGoRoundTheList(): void    {        $this->startPlayer();        $this->clickControl($this->desk->main, 'prev');        self::assertSame(3, $this->wz->playlist->active, 'before the first song: the last one');        $this->clickControl($this->desk->main, 'next');        self::assertSame(0, $this->wz->playlist->active);        $this->clickControl($this->desk->main, 'next');        self::assertSame(1, $this->wz->playlist->active);    }    public function testTheVolumeSliderFollowsThePointer(): void    {        $this->startPlayer();        $this->clickIn($this->desk->main, 6 + 30, 52);        self::assertSame(30, $this->wz->player->volume);        [$x, $y] = $this->at($this->desk->main, 36, 52);        [$x2] = $this->at($this->desk->main, 200, 52);        $this->dragView($x, $y, $x2, $y);        self::assertSame(100, $this->wz->player->volume, 'it stops at 100 %');    }    public function testTheBalanceSliderGoesFromLeftToRight(): void    {        $this->startPlayer();        $this->clickIn($this->desk->main, 142, 52);        self::assertSame(-100, $this->wz->player->balance);        $this->clickIn($this->desk->main, 242, 52);        self::assertSame(100, $this->wz->player->balance);        $this->clickIn($this->desk->main, 192, 52);        self::assertSame(0, $this->wz->player->balance);    }    public function testThePositionBarMovesTheSong(): void    {        $this->startPlayer();        $duration = $this->wz->player->duration();        $this->clickIn($this->desk->main, 6 + 235 / 2, 68);        self::assertSame(Player::PLAYING, $this->wz->player->state, 'let go: it plays from there');        self::assertEqualsWithDelta($duration / 2, $this->wz->player->position, 1.0);    }    public function testHasardIsSwitchedByItsButton(): void    {        $this->startPlayer();        self::assertTrue($this->shuffleAtStart, 'on at the first start (the H button)');        self::assertFalse($this->wz->playlist->shuffle);        $this->clickControl($this->desk->main, 'shuffle');        self::assertTrue($this->wz->playlist->shuffle);        $this->game->shot('hasard-on');        $this->clickControl($this->desk->main, 'shuffle');        self::assertFalse($this->wz->playlist->shuffle);    }    public function testALineOfThePlayListClickedPlays(): void    {        $this->startPlayer();        $list = $this->desk->playlist;        $this->clickIn($list, 120, $list::LIST_TOP + 2 * $list::ROW_HEIGHT + 5);        self::assertSame(2, $this->wz->playlist->active);        self::assertSame(Player::PLAYING, $this->wz->player->state);        self::assertStringEndsWith('chaine-hifi.wav', (string)$this->wz->player->file);    }    public function testTheTitleScrollsOneCharacterEveryFifthOfASecond(): void    {        $this->startPlayer();        $this->wz->playIndex(0);        $before = $this->wz->scrolledTitle();        $shift = $this->wz->titleShift;        $this->game->wait(1);        self::assertSame($shift + 5, $this->wz->titleShift);        self::assertNotSame($before, $this->wz->scrolledTitle());        self::assertStringContainsString('WinZik Band', $this->wz->titleText(), 'artist and title from the ID3 tag');    }    public function testTheBargraphDancesOnlyWhileItPlays(): void    {        $this->startPlayer();        $this->game->wait(0.5);        self::assertLessThan(0.01, $this->wz->vuLeft);        $this->clickControl($this->desk->main, 'play');        $this->game->wait(0.5);        self::assertGreaterThan(0.1, $this->wz->vuLeft);        self::assertGreaterThan(0.1, $this->wz->vuRight);    }    public function testTheSettingsAreKeptForTheNextTime(): void    {        $this->startPlayer();        $this->clickIn($this->desk->main, 6 + 42, 52);        $this->clickControl($this->desk->main, 'shuffle');        $this->wz->save();        $saved = $this->form->engineOrNull()?->storage->readJson('winzik.json');        self::assertIsArray($saved);        self::assertSame(42, $saved['volume']);        self::assertTrue($saved['shuffle']);        self::assertSame(['assets/music/winzik.mp3', 'assets/music/archettes-city.ogg', 'assets/music/chaine-hifi.wav', 'assets/music/partage.mp3'], $saved['playlist']);    }}