Skip to content

Commit

Permalink
Fix test for autoconfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
nkl-kst authored and derrabus committed Oct 21, 2023
1 parent 9652e00 commit 35b74ea
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Fixtures\AsMonologProcessor;

use Monolog\Attribute\AsMonologProcessor;

#[AsMonologProcessor(handler: 'foo_handler')]
class FooProcessorWithPriority
{
#[AsMonologProcessor(channel: 'ccc_channel', priority: '10')]
public function __invoke(): void
{
}
}
34 changes: 32 additions & 2 deletions Tests/DependencyInjection/MonologExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension;
use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass;
use Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Fixtures\AsMonologProcessor\FooProcessor;
use Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Fixtures\AsMonologProcessor\FooProcessorWithPriority;
use Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Fixtures\AsMonologProcessor\RedeclareMethodProcessor;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
Expand Down Expand Up @@ -826,8 +827,8 @@ public function testAsMonologProcessorAutoconfigurationRedeclareMethod(): void
*/
public function testAsMonologProcessorAutoconfiguration(): void
{
if (!\class_exists(AsMonologProcessor::class, true)) {
$this->markTestSkipped('Monolog >= 2.3.6 is needed.');
if (!\class_exists(AsMonologProcessor::class, true) || \property_exists(AsMonologProcessor::class, 'priority')) {
$this->markTestSkipped('Monolog >= 2.3.6 and < 3.4.0 is needed.');
}

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

/**
* @requires PHP 8.0
*/
public function testAsMonologProcessorAutoconfigurationWithPriority(): void
{
if (!\class_exists(AsMonologProcessor::class, true) || !\property_exists(AsMonologProcessor::class, 'priority')) {
$this->markTestSkipped('Monolog >= 3.4.0 is needed.');
}

$container = $this->getContainer([], [
FooProcessorWithPriority::class => (new Definition(FooProcessorWithPriority::class))->setAutoconfigured(true),
]);

$this->assertSame([
[
'channel' => null,
'handler' => 'foo_handler',
'method' => null,
'priority' => null,
],
[
'channel' => 'ccc_channel',
'handler' => null,
'method' => '__invoke',
'priority' => 10,
],
], $container->getDefinition(FooProcessorWithPriority::class)->getTag('monolog.processor'));
}

protected function getContainer(array $config = [], array $thirdPartyDefinitions = [])
{
$container = new ContainerBuilder(new EnvPlaceholderParameterBag());
Expand Down

0 comments on commit 35b74ea

Please sign in to comment.