Files
zombie-game/tests/Unit/Game/RoomTest.php
T
2026-09-07 20:37:40 +02:00

69 lines
2.0 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Game;
use App\Game\EntityList;
use App\Game\InputState;
use App\Game\Player;
use App\Game\Room;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
final class RoomTest extends TestCase
{
#[Test]
public function initialStateIsLobby(): void
{
$room = new Room('test');
$this->assertSame(Room::STATE_LOBBY, $room->state);
}
#[Test]
public function addPlayerIncrementsCount(): void
{
$room = new Room('test');
$player = new Player('p1', 'Alice', new InputState(), $room->entities, $room);
$room->addPlayer($player);
$this->assertCount(1, $room->players);
$this->assertArrayHasKey('p1', $room->players);
}
#[Test]
public function alivePlayersReturnsNonDead(): void
{
$room = new Room('test');
$p1 = new Player('p1', 'A', new InputState(), $room->entities, $room);
$p2 = new Player('p2', 'B', new InputState(), $room->entities, $room);
$room->addPlayer($p1);
$room->addPlayer($p2);
$p1->dead = true;
$this->assertCount(1, $room->alivePlayers());
$this->assertSame('p2', $room->alivePlayers()[0]->id);
}
#[Test]
public function highestScore(): void
{
$room = new Room('test');
$p1 = new Player('p1', 'A', new InputState(), $room->entities, $room);
$p2 = new Player('p2', 'B', new InputState(), $room->entities, $room);
$room->addPlayer($p1);
$room->addPlayer($p2);
$p2->score = 42;
$this->assertSame(42, $room->highestScore());
}
#[Test]
public function pushEventAndFlush(): void
{
$room = new Room('test');
$room->pushEvent('kill', ['x' => 1.0, 'y' => 2.0, 'color' => [1.0, 0.0, 0.0, 1.0]]);
$this->assertCount(1, $room->events);
$this->assertSame('kill', $room->events[0]['k']);
$flushed = $room->flushEvents();
$this->assertCount(1, $flushed);
$this->assertCount(0, $room->events);
}
}