You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When writing a custom Monolog processor as part of a Symfony application, one cannot test this processor using the Monolog\TestCase base class. Indeed this class is part of the autoload-dev section of the composer.json file and this section is only used if the composer.json file is the root one (which is not the case when Monolog is used as part of a Symfony project).
Here is an example of such a test:
<?php
namespace Tests\Bridge\FrontBundle\Logger;
use Bridge\FrontBundle\Logger\RequestIdProcessor;
use Monolog\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
class RequestIdProcessorTest extends TestCase
{
private const REQUEST_ID = 'test-request-id';
public function testValidateRequestIdProcessorWhenRequestIdHeaderIsPresent()
{
$request = new Request([], [], [], [], [], ["HTTP_X_REQUEST_ID" => self::REQUEST_ID]);
$requestStack = new RequestStack();
$requestStack->push($request);
$requestIdProcessor = new RequestIdProcessor($requestStack);
$record = $requestIdProcessor($this->getRecord());
$this->assertArrayHasKey('request_id', $record['extra']);
$this->assertTrue($record['extra']['request_id'] === self::REQUEST_ID);
}
public function testValidateRequestIdProcessorWhenRequestIdHeaderIsMissing()
{
$request = new Request();
$requestStack = new RequestStack();
$requestStack->push($request);
$requestIdProcessor = new RequestIdProcessor($requestStack);
$record = $requestIdProcessor($this->getRecord());
$this->assertArrayHasKey('request_id', $record['extra']);
$this->assertTrue($record['extra']['request_id'] === '-');
}
}
The text was updated successfully, but these errors were encountered:
When writing a custom Monolog processor as part of a Symfony application, one cannot test this processor using the Monolog\TestCase base class. Indeed this class is part of the autoload-dev section of the composer.json file and this section is only used if the composer.json file is the root one (which is not the case when Monolog is used as part of a Symfony project).
Here is an example of such a test:
The text was updated successfully, but these errors were encountered: