InvoiceLogAlertCheckerTest.php
Pfad: tests/Operations/InvoiceLogAlertCheckerTest.php
Ext: php
Größe: 1443 Bytes
Geändert: 2026-07-16 18:07:46+02
<?php
declare(strict_types=1);
use Demo\Operations\InvoiceLogAlertChecker;
use PHPUnit\Framework\TestCase;
final class InvoiceLogAlertCheckerTest extends TestCase
{
public function testReportsOnlyWhitelistedCorrelationFields(): void
{
$path = tempnam(sys_get_temp_dir(), 'invoice-alert-');
self::assertIsString($path);
file_put_contents($path, implode("\n", [
json_encode(['runId' => 'run-1', 'context' => ['errorCode' => 'ERROR_AUTH', 'phase' => 'login', 'password' => 'canary-secret']], JSON_THROW_ON_ERROR),
json_encode(['runId' => 'run-2', 'errorCode' => 'ERROR_DOWNLOAD', 'phase' => 'download'], JSON_THROW_ON_ERROR),
'{invalid',
]));
try {
$result = (new InvoiceLogAlertChecker())->check($path);
} finally {
unlink($path);
}
self::assertSame(3, $result['events']);
self::assertSame([
['runId' => 'run-1', 'code' => 'ERROR_AUTH', 'phase' => 'login'],
['runId' => 'unknown', 'code' => 'UNKNOWN_LOG_FORMAT', 'phase' => 'audit'],
], $result['alerts']);
self::assertStringNotContainsString('canary-secret', json_encode($result, JSON_THROW_ON_ERROR));
}
public function testUnreadableLogFailsClosed(): void
{
$this->expectException(RuntimeException::class);
(new InvoiceLogAlertChecker())->check('/path/does/not/exist');
}
}