repository = new SystemRepository(Database::inMemory()); } public function testReportStatusInsertsSystem(): void { $system = $this->repository->reportStatus('srv1', ['status' => 'ok', 'name' => 'Server 1']); self::assertSame('ok', $system['status']); self::assertSame('api', $system['source']); } public function testReportStatusRejectsInvalidStatus(): void { $this->expectException(InvalidArgumentException::class); $this->repository->reportStatus('srv1', ['status' => 'unknown']); } public function testReportStatusUpdatesExistingSystem(): void { $this->repository->reportStatus('srv1', ['status' => 'ok']); $updated = $this->repository->reportStatus('srv1', ['status' => 'error', 'detail' => 'Timeout']); self::assertSame('error', $updated['status']); self::assertSame('Timeout', $updated['detail']); } public function testImportLegacyRowsDoesNotOverwriteApiSourcedSystem(): void { $this->repository->reportStatus('srv1', ['status' => 'ok']); $this->repository->importLegacyRows([ ['id' => 'srv1', 'name' => 'srv1', 'status' => 'error', 'detail' => '1.2.3.4', 'last_check_at' => '2026-01-01 00:00'], ]); $system = $this->repository->find('srv1'); self::assertSame('ok', $system['status']); self::assertSame('api', $system['source']); } public function testImportLegacyRowsCreatesNewLegacySystem(): void { $this->repository->importLegacyRows([ ['id' => 'srv2', 'name' => 'srv2', 'status' => 'ok', 'detail' => '1.2.3.5', 'last_check_at' => '2026-01-01 00:00'], ]); $system = $this->repository->find('srv2'); self::assertNotNull($system); self::assertSame('legacy', $system['source']); } public function testAllOrdersErrorsFirstAndLimitsToNineTiles(): void { for ($i = 0; $i < 12; $i++) { $this->repository->reportStatus('srv' . $i, ['status' => 'ok']); } $this->repository->reportStatus('broken', ['status' => 'error']); $all = $this->repository->all(); self::assertCount(SystemRepository::MAX_TILES, $all); self::assertSame('error', $all[0]['status']); } public function testFingerprintChangesWhenStatusIsReported(): void { $before = $this->repository->fingerprint(); $this->repository->reportStatus('srv1', ['status' => 'ok']); self::assertNotSame($before, $this->repository->fingerprint()); } }