Files
backend/tests/Unit/Log/TestTraceProcessorTest.php
T
Valery Petrov 77267619ad
backend-ci-cd / parse-tag (push) Has been cancelled
backend-ci-cd / test (push) Has been cancelled
backend-ci-cd / test-prod-skip (push) Has been cancelled
backend-ci-cd / build-and-push (push) Has been cancelled
backend-ci-cd / deploy-gitops (push) Has been cancelled
issues/27: autotest foundation — TestTraceProcessor, PHPUnit suites, CI coverage
2026-06-04 12:51:57 +03:00

45 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Log;
use App\Log\TestTraceProcessor;
use Monolog\Level;
use Monolog\LogRecord;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
final class TestTraceProcessorTest extends TestCase
{
public function testAddsExtraWhenAutoTestHeaderPresent(): void
{
$request = Request::create('/api/test', 'GET');
$request->headers->set('X-Is-Auto-Test', 'true');
$request->headers->set('X-Test-Trace-Id', 'run-42');
$stack = new RequestStack();
$stack->push($request);
$processor = new TestTraceProcessor($stack);
$record = new LogRecord(new \DateTimeImmutable(), 'app', Level::Info, 'msg');
$out = $processor($record);
self::assertTrue($out->extra['is_test']);
self::assertSame('run-42', $out->extra['test_trace_id']);
}
public function testLeavesRecordUntouchedWithoutHeader(): void
{
$stack = new RequestStack();
$processor = new TestTraceProcessor($stack);
$record = new LogRecord(new \DateTimeImmutable(), 'app', Level::Info, 'msg', extra: ['foo' => 1]);
$out = $processor($record);
self::assertSame(['foo' => 1], $out->extra);
}
}