Connexion
FR
games/doom-jumphp / tests / ControlsTest.php · commit 8e1cb9f
<?phpnamespace Tests;use App\Engine\HdRenderer;use PHPUnit\Framework\TestCase;use Symfony\Component\Yaml\Yaml;/** Phones: the on-screen buttons send keys the game binds, a touch is never a shot by itself. */final class ControlsTest extends TestCase{    public function testThePhoneFireAndUseButtonsSendKeysBoundToFireAndUse(): void    {        $project = Yaml::parseFile(dirname(__DIR__) . '/config/project.yaml')['project'];        $actions = Yaml::parseFile(dirname(__DIR__) . '/config/input.yaml')['actions'];        // the page's touch.js knows single letters, arrows, Space, Return, Escape, Tab, Backspace        foreach (['a' => 'fire', 'b' => 'use'] as $button => $action) {            $key = (string)$project['touch'][$button];            self::assertMatchesRegularExpression('/^([A-Z]|Space|Return|Escape|Tab)$/', $key, "button $button");            self::assertContains($key, $actions[$action], "button $button fires '$action'");        }    }    public function testATouchOfTheStickIsNotAShot(): void    {        // on phones a touch is also a mouse click: the mouse must not be bound to "fire"        $actions = Yaml::parseFile(dirname(__DIR__) . '/config/input.yaml')['actions'];        foreach ($actions['fire'] as $binding) {            self::assertStringStartsNotWith('mouse:', (string)$binding);            self::assertStringStartsNotWith('touch:', (string)$binding);        }    }    public function testScale2xDoublesAPictureAndSmoothsItsStaircases(): void    {        // a diagonal staircase of 'a' over 'b'        $px = "abb" . "aab" . "aaa";        $big = HdRenderer::scale2x($px, 3, 3, false);        self::assertSame(36, strlen($big));        self::assertSame('a', $big[0]);        self::assertSame('b', $big[5]);        // the corner of the staircase gets the colour of its neighbours        self::assertSame('a', $big[1 * 6 + 2]);    }}