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/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/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..3e5761dd 100644 --- a/tests/DependencyInjection/SentryExtensionTest.php +++ b/tests/DependencyInjection/SentryExtensionTest.php @@ -25,6 +25,7 @@ use Sentry\SentryBundle\EventListener\TracingSubRequestListener; use Sentry\SentryBundle\Integration\IntegrationConfigurator; use Sentry\SentryBundle\SentryBundle; +use Sentry\SentryBundle\Serializer\ConsoleInputSerializer; use Sentry\SentryBundle\Tracing\Doctrine\DBAL\ConnectionConfigurator; use Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverMiddleware; use Sentry\SentryBundle\Tracing\Twig\TwigTracingExtension; @@ -32,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; @@ -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 * 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']); + } +}