Skip to content

Commit

Permalink
minor #464 Fix test for autoconfiguration (nkl-kst)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 3.x-dev branch.

Discussion
----------

Fix test for autoconfiguration

This PR contains two small fixes for the Monolog processor autoconfiguration test. The test currently fails because of changes in Seldaek/monolog#1797.

Not sure if I should provide more information. Please let me know if I missed something 🙂

Commits
-------

35b74ea Fix test for autoconfiguration
  • Loading branch information
derrabus committed Oct 21, 2023
2 parents 9652e00 + 35b74ea commit 67ed61d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
@@ -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
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 67ed61d

Please sign in to comment.