|
12 | 12 | namespace Symfony\Bundle\MonologBundle\Tests\DependencyInjection; |
13 | 13 |
|
14 | 14 | use InvalidArgumentException; |
| 15 | +use Monolog\Attribute\AsMonologProcessor; |
15 | 16 | use Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy; |
16 | 17 | use Monolog\Handler\RollbarHandler; |
17 | 18 | use Monolog\Logger; |
18 | 19 | use Monolog\Processor\UidProcessor; |
19 | 20 | use Symfony\Bridge\Monolog\Processor\SwitchUserTokenProcessor; |
20 | 21 | use Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension; |
21 | 22 | use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass; |
| 23 | +use Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Fixtures\AsMonologProcessor\FooProcessor; |
| 24 | +use Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Fixtures\AsMonologProcessor\RedeclareMethodProcessor; |
22 | 25 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
23 | 26 | use Symfony\Component\DependencyInjection\Definition; |
24 | 27 | use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag; |
@@ -816,6 +819,50 @@ public function testProcessorAutoConfiguration() |
816 | 819 | $this->assertEquals('reset', $tags['kernel.reset'][0]['method']); |
817 | 820 | } |
818 | 821 |
|
| 822 | + /** |
| 823 | + * @requires PHP 8.0 |
| 824 | + */ |
| 825 | + public function testAsMonologProcessorAutoconfigurationRedeclareMethod(): void |
| 826 | + { |
| 827 | + if (!\class_exists(AsMonologProcessor::class, true)) { |
| 828 | + $this->markTestSkipped('Monolog >= 2.3.6 is needed.'); |
| 829 | + } |
| 830 | + |
| 831 | + $this->expectException(\LogicException::class); |
| 832 | + $this->expectExceptionMessage('AsMonologProcessor attribute cannot declare a method on "Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Fixtures\AsMonologProcessor\RedeclareMethodProcessor::__invoke()".'); |
| 833 | + |
| 834 | + $this->getContainer([], [ |
| 835 | + RedeclareMethodProcessor::class => (new Definition(RedeclareMethodProcessor::class))->setAutoconfigured(true), |
| 836 | + ]); |
| 837 | + } |
| 838 | + |
| 839 | + /** |
| 840 | + * @requires PHP 8.0 |
| 841 | + */ |
| 842 | + public function testAsMonologProcessorAutoconfiguration(): void |
| 843 | + { |
| 844 | + if (!\class_exists(AsMonologProcessor::class, true)) { |
| 845 | + $this->markTestSkipped('Monolog >= 2.3.6 is needed.'); |
| 846 | + } |
| 847 | + |
| 848 | + $container = $this->getContainer([], [ |
| 849 | + FooProcessor::class => (new Definition(FooProcessor::class))->setAutoconfigured(true), |
| 850 | + ]); |
| 851 | + |
| 852 | + $this->assertSame([ |
| 853 | + [ |
| 854 | + 'channel' => null, |
| 855 | + 'handler' => 'foo_handler', |
| 856 | + 'method' => null, |
| 857 | + ], |
| 858 | + [ |
| 859 | + 'channel' => 'ccc_channel', |
| 860 | + 'handler' => null, |
| 861 | + 'method' => '__invoke', |
| 862 | + ], |
| 863 | + ], $container->getDefinition(FooProcessor::class)->getTag('monolog.processor')); |
| 864 | + } |
| 865 | + |
819 | 866 | protected function getContainer(array $config = [], array $thirdPartyDefinitions = []) |
820 | 867 | { |
821 | 868 | $container = new ContainerBuilder(new EnvPlaceholderParameterBag()); |
|
0 commit comments