Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,7 @@ services:
tags:
- { name: twig.extension }

# Serializers
Sentry\SentryBundle\Serializer\ConsoleInputSerializer: ~


24 changes: 24 additions & 0 deletions src/Serializer/ConsoleInputSerializer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Sentry\SentryBundle\Serializer;

use Symfony\Component\Console\Input\InputInterface;

/**
* @author Sylvain Fabre
*/
final class ConsoleInputSerializer
{
/**
* @return array{arguments: array<string, mixed>, options: array<string, mixed>}
*/
public function __invoke(InputInterface $input): array
{
return [
'arguments' => $input->getArguments(),
'options' => $input->getOptions(),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

use Symfony\Component\DependencyInjection\ContainerBuilder;

/** @var ContainerBuilder $container */
$container->loadFromExtension('sentry', [
'options' => [
'class_serializers' => [
'Symfony\\Component\\Console\\Input\\InputInterface' => 'Sentry\\SentryBundle\\Serializer\\ConsoleInputSerializer',
],
],
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sentry="https://sentry.io/schema/dic/sentry-symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
https://sentry.io/schema/dic/sentry-symfony https://sentry.io/schema/dic/sentry-symfony/sentry-1.0.xsd">

<sentry:config>
<sentry:options>
<sentry:class-serializer class="Symfony\Component\Console\Input\InputInterface">Sentry\SentryBundle\Serializer\ConsoleInputSerializer</sentry:class-serializer>
</sentry:options>
</sentry:config>
</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sentry:
options:
class_serializers:
Symfony\Component\Console\Input\InputInterface: Sentry\SentryBundle\Serializer\ConsoleInputSerializer
15 changes: 15 additions & 0 deletions tests/DependencyInjection/SentryExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@
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;
use Sentry\Serializer\RepresentationSerializer;
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;
Expand Down Expand Up @@ -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
*
Expand Down
32 changes: 32 additions & 0 deletions tests/Serializer/ConsoleInputSerializerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Sentry\SentryBundle\Tests\Serializer;

use PHPUnit\Framework\TestCase;
use Sentry\SentryBundle\Serializer\ConsoleInputSerializer;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;

final class ConsoleInputSerializerTest extends TestCase
{
public function testInvokeReturnsArgumentsAndOptions(): void
{
$definition = new InputDefinition([
new InputArgument('name', InputArgument::REQUIRED),
new InputOption('verbose', 'v', InputOption::VALUE_NONE),
]);

$input = new ArrayInput(['name' => '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']);
}
}
Loading