Files
zombie-game/tests/Unit/Game/StressTestHarnessTest.php
T
2026-09-08 22:33:51 +02:00

77 lines
2.6 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Game;
use App\Game\StressTestHarness;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
final class StressTestHarnessTest extends TestCase
{
private function harness(): StressTestHarness
{
return new StressTestHarness;
}
#[Test]
public function tick_report_has_expected_shape(): void
{
$report = $this->harness()->measureTickTime(50, players: 2, ticks: 20);
$this->assertSame(50, $report['entities']);
$this->assertArrayHasKey('zombies', $report['scenarios']);
$this->assertArrayHasKey('projectiles', $report['scenarios']);
foreach ($report['scenarios'] as $result) {
$this->assertArrayHasKey('avgMs', $result);
$this->assertArrayHasKey('medianMs', $result);
$this->assertArrayHasKey('maxMs', $result);
$this->assertArrayHasKey('budgetOk', $result);
}
}
#[Test]
public function tick_time_is_measured_as_positive(): void
{
$report = $this->harness()->measureTickTime(50, players: 2, ticks: 20);
foreach ($report['scenarios'] as $result) {
$this->assertGreaterThan(0.0, $result['avgMs']);
$this->assertGreaterThan(0.0, $result['maxMs']);
}
}
#[Test]
public function snapshot_bytes_grow_with_entity_count(): void
{
$small = $this->harness()->measureSnapshotBytes(50, players: 2, scenarios: ['zombies']);
$large = $this->harness()->measureSnapshotBytes(400, players: 2, scenarios: ['zombies']);
$this->assertGreaterThan(
$small['scenarios']['zombies']['bytes'],
$large['scenarios']['zombies']['bytes'],
'snapshot payload should grow as entity count grows',
);
}
#[Test]
public function snapshot_report_tracks_bytes_per_entity(): void
{
$report = $this->harness()->measureSnapshotBytes(100, players: 2, scenarios: ['zombies']);
$this->assertGreaterThan(0, $report['scenarios']['zombies']['bytes']);
$this->assertGreaterThan(0.0, $report['scenarios']['zombies']['bytesPerEntity']);
}
#[Test]
public function reverb_cap_flag_flips_between_small_and_large_rooms(): void
{
$small = $this->harness()->measureSnapshotBytes(50, players: 2, scenarios: ['zombies']);
$large = $this->harness()->measureSnapshotBytes(2000, players: 2, scenarios: ['zombies']);
$this->assertFalse($small['scenarios']['zombies']['exceedsReverb']);
$this->assertTrue($large['scenarios']['zombies']['exceedsReverb']);
}
}