Files
breadcrumb-the-shire/tests/Architecture/SecurityLoggingRuntimeContractTest.php

40 lines
1.4 KiB
PHP
Raw Normal View History

2026-03-19 19:08:28 +01:00
<?php
namespace MintyPHP\Tests\Architecture;
use PHPUnit\Framework\TestCase;
final class SecurityLoggingRuntimeContractTest extends TestCase
{
use ProjectFileAssertionSupport;
public function testFrontendTelemetryIngestUsesOnlyRequestScopedErrorLogFallback(): void
{
$violations = array_merge(
$this->findPatternMatchesInPhpFiles('lib', '/\berror_log\s*\(/'),
$this->findPatternMatchesInPhpFiles('pages', '/\berror_log\s*\(/')
);
sort($violations);
self::assertSame(
['pages/admin/frontend-telemetry/ingest().php'],
$violations,
"Unexpected error_log() usage outside the telemetry ingest fallback:\n" . implode("\n", $violations)
);
$content = $this->readProjectFile('pages/admin/frontend-telemetry/ingest().php');
self::assertStringContainsString(
"error_log('[frontend-telemetry] ingest record_failed request_id=' . RequestContext::id());",
$content
);
preg_match('/^.*\berror_log\s*\(.*$/m', $content, $matches);
$errorLogLine = $matches[0] ?? '';
self::assertNotSame('', $errorLogLine, 'Expected a dedicated telemetry error_log() fallback line.');
self::assertStringNotContainsString('$payload', $errorLogLine);
self::assertStringNotContainsString('$record', $errorLogLine);
self::assertStringNotContainsString('$events', $errorLogLine);
}
}