Skip to content

Commit 35b74ea

Browse files
nkl-kstderrabus
authored andcommitted
Fix test for autoconfiguration
1 parent 9652e00 commit 35b74ea

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Fixtures\AsMonologProcessor;
13+
14+
use Monolog\Attribute\AsMonologProcessor;
15+
16+
#[AsMonologProcessor(handler: 'foo_handler')]
17+
class FooProcessorWithPriority
18+
{
19+
#[AsMonologProcessor(channel: 'ccc_channel', priority: '10')]
20+
public function __invoke(): void
21+
{
22+
}
23+
}

Tests/DependencyInjection/MonologExtensionTest.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension;
2222
use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass;
2323
use Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Fixtures\AsMonologProcessor\FooProcessor;
24+
use Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Fixtures\AsMonologProcessor\FooProcessorWithPriority;
2425
use Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Fixtures\AsMonologProcessor\RedeclareMethodProcessor;
2526
use Symfony\Component\DependencyInjection\ContainerBuilder;
2627
use Symfony\Component\DependencyInjection\Definition;
@@ -826,8 +827,8 @@ public function testAsMonologProcessorAutoconfigurationRedeclareMethod(): void
826827
*/
827828
public function testAsMonologProcessorAutoconfiguration(): void
828829
{
829-
if (!\class_exists(AsMonologProcessor::class, true)) {
830-
$this->markTestSkipped('Monolog >= 2.3.6 is needed.');
830+
if (!\class_exists(AsMonologProcessor::class, true) || \property_exists(AsMonologProcessor::class, 'priority')) {
831+
$this->markTestSkipped('Monolog >= 2.3.6 and < 3.4.0 is needed.');
831832
}
832833

833834
$container = $this->getContainer([], [
@@ -848,6 +849,35 @@ public function testAsMonologProcessorAutoconfiguration(): void
848849
], $container->getDefinition(FooProcessor::class)->getTag('monolog.processor'));
849850
}
850851

852+
/**
853+
* @requires PHP 8.0
854+
*/
855+
public function testAsMonologProcessorAutoconfigurationWithPriority(): void
856+
{
857+
if (!\class_exists(AsMonologProcessor::class, true) || !\property_exists(AsMonologProcessor::class, 'priority')) {
858+
$this->markTestSkipped('Monolog >= 3.4.0 is needed.');
859+
}
860+
861+
$container = $this->getContainer([], [
862+
FooProcessorWithPriority::class => (new Definition(FooProcessorWithPriority::class))->setAutoconfigured(true),
863+
]);
864+
865+
$this->assertSame([
866+
[
867+
'channel' => null,
868+
'handler' => 'foo_handler',
869+
'method' => null,
870+
'priority' => null,
871+
],
872+
[
873+
'channel' => 'ccc_channel',
874+
'handler' => null,
875+
'method' => '__invoke',
876+
'priority' => 10,
877+
],
878+
], $container->getDefinition(FooProcessorWithPriority::class)->getTag('monolog.processor'));
879+
}
880+
851881
protected function getContainer(array $config = [], array $thirdPartyDefinitions = [])
852882
{
853883
$container = new ContainerBuilder(new EnvPlaceholderParameterBag());

0 commit comments

Comments
 (0)