issues/27: autotest foundation — TestTraceProcessor, PHPUnit suites, CI coverage
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
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
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user