From 86caf578ab3328ce87a6522cc62d81b8111d5f74 Mon Sep 17 00:00:00 2001 From: Sylvain Fabre Date: Fri, 13 Mar 2026 13:11:48 +0100 Subject: [PATCH 1/3] feat: add ConsoleInputSerializer for console command arguments and options --- src/Resources/config/services.yaml | 3 ++ src/Serializer/ConsoleInputSerializer.php | 24 ++++++++++++++ .../Serializer/ConsoleInputSerializerTest.php | 32 +++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 src/Serializer/ConsoleInputSerializer.php create mode 100644 tests/Serializer/ConsoleInputSerializerTest.php diff --git a/src/Resources/config/services.yaml b/src/Resources/config/services.yaml index 594eea40..5b09a2e9 100644 --- a/src/Resources/config/services.yaml +++ b/src/Resources/config/services.yaml @@ -135,4 +135,7 @@ services: tags: - { name: twig.extension } + # Serializers + Sentry\SentryBundle\Serializer\ConsoleInputSerializer: ~ + diff --git a/src/Serializer/ConsoleInputSerializer.php b/src/Serializer/ConsoleInputSerializer.php new file mode 100644 index 00000000..a221fbda --- /dev/null +++ b/src/Serializer/ConsoleInputSerializer.php @@ -0,0 +1,24 @@ +, options: array} + */ + public function __invoke(InputInterface $input): array + { + return [ + 'arguments' => $input->getArguments(), + 'options' => $input->getOptions(), + ]; + } +} diff --git a/tests/Serializer/ConsoleInputSerializerTest.php b/tests/Serializer/ConsoleInputSerializerTest.php new file mode 100644 index 00000000..3c2d975e --- /dev/null +++ b/tests/Serializer/ConsoleInputSerializerTest.php @@ -0,0 +1,32 @@ + 'foo', '--verbose' => true], $definition); + + $serializer = new ConsoleInputSerializer(); + $result = $serializer($input); + + $this->assertSame(['name' => 'foo'], $result['arguments']); + $this->assertArrayHasKey('verbose', $result['options']); + $this->assertTrue($result['options']['verbose']); + } +} From 92425a88984941fddab5aeb00c813f1a504447ea Mon Sep 17 00:00:00 2001 From: Sylvain Fabre Date: Tue, 17 Mar 2026 12:27:38 +0100 Subject: [PATCH 2/3] test: add integration test for ConsoleInputSerializer DI registration Verifies that ConsoleInputSerializer is registered in the service container and properly resolves as a Reference when configured as a class_serializer. Co-Authored-By: Claude Sonnet 4.6 --- .../Fixtures/php/console_input_serializer.php | 14 ++++++++++++++ .../Fixtures/xml/console_input_serializer.xml | 14 ++++++++++++++ .../Fixtures/yml/console_input_serializer.yml | 4 ++++ tests/DependencyInjection/SentryExtensionTest.php | 15 +++++++++++++++ 4 files changed, 47 insertions(+) create mode 100644 tests/DependencyInjection/Fixtures/php/console_input_serializer.php create mode 100644 tests/DependencyInjection/Fixtures/xml/console_input_serializer.xml create mode 100644 tests/DependencyInjection/Fixtures/yml/console_input_serializer.yml diff --git a/tests/DependencyInjection/Fixtures/php/console_input_serializer.php b/tests/DependencyInjection/Fixtures/php/console_input_serializer.php new file mode 100644 index 00000000..68b46b9f --- /dev/null +++ b/tests/DependencyInjection/Fixtures/php/console_input_serializer.php @@ -0,0 +1,14 @@ +loadFromExtension('sentry', [ + 'options' => [ + 'class_serializers' => [ + 'Symfony\\Component\\Console\\Input\\InputInterface' => 'Sentry\\SentryBundle\\Serializer\\ConsoleInputSerializer', + ], + ], +]); diff --git a/tests/DependencyInjection/Fixtures/xml/console_input_serializer.xml b/tests/DependencyInjection/Fixtures/xml/console_input_serializer.xml new file mode 100644 index 00000000..9a8b0753 --- /dev/null +++ b/tests/DependencyInjection/Fixtures/xml/console_input_serializer.xml @@ -0,0 +1,14 @@ + + + + + + + Sentry\SentryBundle\Serializer\ConsoleInputSerializer + + + diff --git a/tests/DependencyInjection/Fixtures/yml/console_input_serializer.yml b/tests/DependencyInjection/Fixtures/yml/console_input_serializer.yml new file mode 100644 index 00000000..7eda76f5 --- /dev/null +++ b/tests/DependencyInjection/Fixtures/yml/console_input_serializer.yml @@ -0,0 +1,4 @@ +sentry: + options: + class_serializers: + Symfony\Component\Console\Input\InputInterface: Sentry\SentryBundle\Serializer\ConsoleInputSerializer diff --git a/tests/DependencyInjection/SentryExtensionTest.php b/tests/DependencyInjection/SentryExtensionTest.php index 07fbe2ef..683a1611 100644 --- a/tests/DependencyInjection/SentryExtensionTest.php +++ b/tests/DependencyInjection/SentryExtensionTest.php @@ -25,6 +25,8 @@ use Sentry\SentryBundle\EventListener\TracingSubRequestListener; use Sentry\SentryBundle\Integration\IntegrationConfigurator; use Sentry\SentryBundle\SentryBundle; +use Sentry\SentryBundle\Serializer\ConsoleInputSerializer; +use Symfony\Component\Console\Input\InputInterface; use Sentry\SentryBundle\Tracing\Doctrine\DBAL\ConnectionConfigurator; use Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverMiddleware; use Sentry\SentryBundle\Tracing\Twig\TwigTracingExtension; @@ -349,6 +351,19 @@ public function testErrorTypesOptionIsParsedFromStringToIntegerValue(): void $this->assertSame(\E_ALL & ~(\E_NOTICE | 2048 | \E_DEPRECATED), $optionsDefinition->getArgument(0)['error_types']); } + public function testConsoleInputSerializerIsRegisteredAndResolvesAsClassSerializer(): void + { + $container = $this->createContainerFromFixture('console_input_serializer'); + + $this->assertTrue($container->hasDefinition(ConsoleInputSerializer::class)); + + $optionsDefinition = $container->getDefinition('sentry.client.options'); + $classSerializers = $optionsDefinition->getArgument(0)['class_serializers']; + + $this->assertArrayHasKey(InputInterface::class, $classSerializers); + $this->assertEquals(new Reference(ConsoleInputSerializer::class), $classSerializers[InputInterface::class]); + } + /** * @dataProvider dsnOptionIsSetOnClientOptionsDataProvider * From e2c7ded8363aa768f87d842a7ea172233bdb9d5d Mon Sep 17 00:00:00 2001 From: Sylvain Fabre Date: Mon, 30 Mar 2026 22:18:22 +0200 Subject: [PATCH 3/3] fix: fix CS and PHPStan issues in integration test Co-Authored-By: Claude Sonnet 4.6 --- phpstan-baseline.neon | 10 ++++++++++ tests/DependencyInjection/SentryExtensionTest.php | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 86d7c41f..653612a7 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -305,11 +305,21 @@ parameters: count: 1 path: tests/DependencyInjection/SentryExtensionTest.php + - + message: "#^Cannot access offset 'class_serializers' on mixed\\.$#" + count: 1 + path: tests/DependencyInjection/SentryExtensionTest.php + - message: "#^Cannot access offset 'release' on mixed\\.$#" count: 1 path: tests/DependencyInjection/SentryExtensionTest.php + - + message: "#^Parameter \\#2 \\$array of method PHPUnit\\\\Framework\\\\Assert\\:\\:assertArrayHasKey\\(\\) expects array\\|ArrayAccess, mixed given\\.$#" + count: 1 + path: tests/DependencyInjection/SentryExtensionTest.php + - message: "#^Class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Client not found\\.$#" count: 1 diff --git a/tests/DependencyInjection/SentryExtensionTest.php b/tests/DependencyInjection/SentryExtensionTest.php index 683a1611..3e5761dd 100644 --- a/tests/DependencyInjection/SentryExtensionTest.php +++ b/tests/DependencyInjection/SentryExtensionTest.php @@ -26,7 +26,6 @@ use Sentry\SentryBundle\Integration\IntegrationConfigurator; use Sentry\SentryBundle\SentryBundle; use Sentry\SentryBundle\Serializer\ConsoleInputSerializer; -use Symfony\Component\Console\Input\InputInterface; use Sentry\SentryBundle\Tracing\Doctrine\DBAL\ConnectionConfigurator; use Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverMiddleware; use Sentry\SentryBundle\Tracing\Twig\TwigTracingExtension; @@ -34,6 +33,7 @@ use Sentry\State\HubInterface; use Symfony\Bundle\TwigBundle\TwigBundle; use Symfony\Component\Console\ConsoleEvents; +use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass; use Symfony\Component\DependencyInjection\Compiler\ResolveTaggedIteratorArgumentPass; use Symfony\Component\DependencyInjection\Compiler\ValidateEnvPlaceholdersPass;