Some improvements

This commit is contained in:
armel committed 2026-09-08 22:33:51 +02:00
1 parent a914bd74fe
commit 729c0be834
16 files changed
+577 -36

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use App\Events\GameSnapshot;
use App\Game\Room;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
final class GameSnapshotTest extends TestCase
{
#[Test]
public function broadcast_payload_discloses_message_size_cap(): void
{
$room = new Room('test');
$payload = (new GameSnapshot($room, [], [], []))->broadcastWith();
$this->assertArrayHasKey('msgCap', $payload);
$this->assertSame(
(int) config('reverb.apps.apps.0.max_message_size', 0),
$payload['msgCap'],
'client debug HUD reports the same cap the Reverb server enforces',
);
}
}
+50
View File
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
final class GameStressTestTest extends TestCase
{
#[Test]
public function unknown_scenario_rejects_with_failure(): void
{
$this->artisan('game:stress', ['--scenario' => 'aliens'])
->expectsOutputToContain('Unknown scenario')
->assertExitCode(1);
}
#[Test]
public function step_below_one_rejects_with_failure(): void
{
$this->artisan('game:stress', ['--step' => '0'])
->expectsOutputToContain('Invalid sweep range')
->assertExitCode(1);
}
#[Test]
public function inverted_range_rejects_with_failure(): void
{
$this->artisan('game:stress', ['--entities-from' => '200', '--entities-to' => '100'])
->expectsOutputToContain('Invalid sweep range')
->assertExitCode(1);
}
#[Test]
public function breakpoint_run_reports_capacity_limits(): void
{
$this->artisan('game:stress', [
'--entities-from' => '50',
'--entities-to' => '50',
'--step' => '50',
'--ticks' => '5',
'--breakpoint-only' => true,
])
->expectsOutputToContain('Derived capacity limits')
->expectsOutputToContain('Reverb cap')
->assertExitCode(0);
}
}
+76
View File
@@ -0,0 +1,76 @@
<?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']);
}
}