Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Resources/config/processors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ services:
- setEnvironment:
- '%kernel.environment%'
- setTokenStorage:
- '@security.token_storage'
- '@?security.token_storage'
- setRequestStack:
- '@request_stack'
- '@?request_stack'

Deamon\LoggerExtraBundle\Processors\Monolog\DeamonLoggerExtraWebProcessor:
alias: deamon.logger_extra.processors.web_processor
Expand Down
39 changes: 39 additions & 0 deletions Tests/DependencyInjection/DeamonLoggerExtraExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

use Deamon\LoggerExtraBundle\DependencyInjection\DeamonLoggerExtraExtension;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\DependencyInjection\Reference;

class DeamonLoggerExtraExtensionTest extends TestCase
{
Expand Down Expand Up @@ -120,6 +124,21 @@ public function testConvertStringHandlerToArray(): void
$this->assertEquals('bar', $tag[0]['handler']);
}

public function testOptionalServiceReferencesUseIgnoreOnInvalidBehavior(): void
{
$loader = new YamlFileLoader(
$this->container,
new FileLocator(__DIR__ . '/../../Resources/config')
);
$loader->load('processors.yaml');

$definition = $this->container->getDefinition('deamon.logger_extra.processors.web_processor');
$methodCalls = $definition->getMethodCalls();

$this->assertReferenceUsesIgnoreOnInvalidBehavior($methodCalls, 'setTokenStorage');
$this->assertReferenceUsesIgnoreOnInvalidBehavior($methodCalls, 'setRequestStack');
}

/**
* @return array
*/
Expand Down Expand Up @@ -163,4 +182,24 @@ private function getValidConfigMin(): array
'config' => null,
];
}

/**
* @param array<int, array{0: string, 1: array<int, mixed>}> $methodCalls
*/
private function assertReferenceUsesIgnoreOnInvalidBehavior(array $methodCalls, string $methodName): void
{
foreach ($methodCalls as $methodCall) {
if ($methodCall[0] !== $methodName) {
continue;
}

$this->assertCount(1, $methodCall[1]);
$this->assertInstanceOf(Reference::class, $methodCall[1][0]);
$this->assertSame(ContainerInterface::IGNORE_ON_INVALID_REFERENCE, $methodCall[1][0]->getInvalidBehavior());

return;
}

$this->fail(sprintf('Method call "%s" was not found.', $methodName));
}
}
Loading