Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0981943

Browse filesBrowse files
committed
remove not needed tests and improved FlatternExceptionNormalizer
1 parent f2a0737 commit 0981943
Copy full SHA for 0981943

File tree

Expand file treeCollapse file tree

4 files changed

+36
-77
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+36
-77
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.xml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
<service id="Symfony\Component\Serializer\Normalizer\ObjectNormalizer" alias="serializer.normalizer.object" />
8585

8686
<service id="serializer.normalizer.flatten_exception" class="Symfony\Component\Serializer\Normalizer\FlattenExceptionNormalizer">
87-
<tag name="serializer.normalizer" />
87+
<tag name="serializer.normalizer" priority="-800" />
8888
</service>
8989

9090
<service id="serializer.denormalizer.array" class="Symfony\Component\Serializer\Normalizer\ArrayDenormalizer">

‎src/Symfony/Component/Messenger/EventListener/SendFailedMessageForRetryListener.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/EventListener/SendFailedMessageForRetryListener.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use Psr\Container\ContainerInterface;
1414
use Psr\Log\LoggerInterface;
15+
use Symfony\Component\ErrorHandler\Exception\FlattenException;
1516
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1617
use Symfony\Component\Messenger\Envelope;
1718
use Symfony\Component\Messenger\Event\WorkerMessageFailedEvent;
@@ -67,7 +68,7 @@ public function onMessageFailed(WorkerMessageFailedEvent $event)
6768
}
6869

6970
// add the delay and retry stamp info
70-
$retryEnvelope = $this->withLimitedHistory($envelope, new DelayStamp($delay), new RedeliveryStamp($retryCount));
71+
$retryEnvelope = $this->withLimitedHistory($envelope, new DelayStamp($delay), new RedeliveryStamp($retryCount, $throwable->getMessage(), FlattenException::createFromThrowable($throwable)));
7172

7273
// re-send the message for retry
7374
$this->getSenderForTransport($event->getReceiverName())->send($retryEnvelope);

‎src/Symfony/Component/Serializer/Normalizer/FlattenExceptionNormalizer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/FlattenExceptionNormalizer.php
+21-32Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,23 @@
1313

1414
use Symfony\Component\ErrorHandler\Exception\FlattenException;
1515
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
16-
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
1716

1817
/**
1918
* Normalizes FlattenException instances.
2019
*
2120
* @author Pascal Luna <skalpa@zetareticuli.org>
2221
*/
23-
class FlattenExceptionNormalizer implements NormalizerInterface, DenormalizerInterface, CacheableSupportsMethodInterface
22+
final class FlattenExceptionNormalizer implements NormalizerInterface, DenormalizerInterface, CacheableSupportsMethodInterface
2423
{
24+
use NormalizerAwareTrait;
25+
2526
/**
2627
* {@inheritdoc}
2728
*
2829
* @throws InvalidArgumentException
2930
*/
3031
public function normalize($object, $format = null, array $context = [])
3132
{
32-
if (!$object instanceof FlattenException) {
33-
throw new InvalidArgumentException(sprintf('The object must be an instance of "%s".', FlattenException::class));
34-
}
35-
3633
$normalized = [
3734
'message' => $object->getMessage(),
3835
'code' => $object->getCode(),
@@ -47,7 +44,7 @@ public function normalize($object, $format = null, array $context = [])
4744
if (null !== $status = $object->getStatusCode()) {
4845
$normalized['status'] = $status;
4946
}
50-
47+
5148
return $normalized;
5249
}
5350

@@ -64,36 +61,28 @@ public function supportsNormalization($data, $format = null)
6461
*/
6562
public function denormalize($data, $type, $format = null, array $context = [])
6663
{
67-
if (!\is_array($data)) {
68-
throw new NotNormalizableValueException(sprintf('The normalized data must be an array, got "%s".', \is_object($data) ? \get_class($data) : \gettype($data)));
69-
}
70-
7164
$object = new FlattenException();
72-
73-
$object->setMessage($data['message'] ?? null);
74-
$object->setCode($data['code'] ?? null);
65+
66+
$object->setMessage($data['message']);
67+
$object->setCode($data['code']);
7568
$object->setStatusCode($data['status'] ?? null);
76-
$object->setClass($data['class'] ?? null);
77-
$object->setFile($data['file'] ?? null);
78-
$object->setLine($data['line'] ?? null);
79-
80-
if (isset($data['headers'])) {
81-
$object->setHeaders((array) $data['headers']);
82-
}
69+
$object->setClass($data['class']);
70+
$object->setFile($data['file']);
71+
$object->setLine($data['line']);
72+
$object->setHeaders((array) $data['headers']);
73+
8374
if (isset($data['previous'])) {
8475
$object->setPrevious($this->denormalize($data['previous'], $type, $format, $context));
8576
}
86-
if (isset($data['trace'])) {
87-
$property = new \ReflectionProperty(FlattenException::class, 'trace');
88-
$property->setAccessible(true);
89-
$property->setValue($object, (array) $data['trace']);
90-
}
91-
if (isset($data['trace_as_string'])) {
92-
$property = new \ReflectionProperty(FlattenException::class, 'traceAsString');
93-
$property->setAccessible(true);
94-
$property->setValue($object, $data['trace_as_string']);
95-
}
96-
77+
78+
$property = new \ReflectionProperty(FlattenException::class, 'trace');
79+
$property->setAccessible(true);
80+
$property->setValue($object, (array) $data['trace']);
81+
82+
$property = new \ReflectionProperty(FlattenException::class, 'traceAsString');
83+
$property->setAccessible(true);
84+
$property->setValue($object, $data['trace_as_string']);
85+
9786
return $object;
9887
}
9988

‎src/Symfony/Component/Serializer/Tests/Normalizer/FlattenExceptionNormalizerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/Normalizer/FlattenExceptionNormalizerTest.php
+12-43Lines changed: 12 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,12 @@ public function testNormalize(FlattenException $exception)
6565
public function provideFlattenException(): array
6666
{
6767
return [
68-
'instance from constructor' => [new FlattenException()],
6968
'instance from exception' => [FlattenException::createFromThrowable(new \RuntimeException('foo', 42))],
7069
'instance with previous exception' => [FlattenException::createFromThrowable(new \RuntimeException('foo', 42, new \Exception()))],
7170
'instance with headers' => [FlattenException::createFromThrowable(new \RuntimeException('foo', 42), 404, ['Foo' => 'Bar'])],
7271
];
7372
}
74-
75-
public function testNormalizeBadObjectTypeThrowsException()
76-
{
77-
$this->expectException(InvalidArgumentException::class);
78-
$this->normalizer->normalize(new \stdClass());
79-
}
80-
73+
8174
public function testSupportsDenormalization()
8275
{
8376
$this->assertTrue($this->normalizer->supportsDenormalization(null, FlattenException::class));
@@ -86,21 +79,6 @@ public function testSupportsDenormalization()
8679

8780
public function testDenormalizeValidData()
8881
{
89-
$normalized = [];
90-
$exception = $this->normalizer->denormalize($normalized, FlattenException::class);
91-
92-
$this->assertInstanceOf(FlattenException::class, $exception);
93-
$this->assertNull($exception->getMessage());
94-
$this->assertNull($exception->getCode());
95-
$this->assertNull($exception->getStatusCode());
96-
$this->assertNull($exception->getHeaders());
97-
$this->assertNull($exception->getClass());
98-
$this->assertNull($exception->getFile());
99-
$this->assertNull($exception->getLine());
100-
$this->assertNull($exception->getPrevious());
101-
$this->assertNull($exception->getTrace());
102-
$this->assertNull($exception->getTraceAsString());
103-
10482
$normalized = [
10583
'message' => 'Something went foobar.',
10684
'code' => 42,
@@ -112,6 +90,16 @@ public function testDenormalizeValidData()
11290
'previous' => [
11391
'message' => 'Previous exception',
11492
'code' => 0,
93+
'class' => FlattenException::class,
94+
'file' => 'foo.php',
95+
'line' => 123,
96+
'headers' => ['Content-Type' => 'application/json'],
97+
'trace' => [
98+
[
99+
'namespace' => '', 'short_class' => '', 'class' => '', 'type' => '', 'function' => '', 'file' => 'foo.php', 'line' => 123, 'args' => [],
100+
],
101+
],
102+
'trace_as_string' => '#0 foo.php(123): foo()'.PHP_EOL.'#1 bar.php(456): bar()',
115103
],
116104
'trace' => [
117105
[
@@ -121,7 +109,7 @@ public function testDenormalizeValidData()
121109
'trace_as_string' => '#0 foo.php(123): foo()'.PHP_EOL.'#1 bar.php(456): bar()',
122110
];
123111
$exception = $this->normalizer->denormalize($normalized, FlattenException::class);
124-
112+
125113
$this->assertInstanceOf(FlattenException::class, $exception);
126114
$this->assertSame($normalized['message'], $exception->getMessage());
127115
$this->assertSame($normalized['code'], $exception->getCode());
@@ -137,23 +125,4 @@ public function testDenormalizeValidData()
137125
$this->assertSame($normalized['previous']['message'], $previous->getMessage());
138126
$this->assertSame($normalized['previous']['code'], $previous->getCode());
139127
}
140-
141-
/**
142-
* @dataProvider provideInvalidNormalizedData
143-
*/
144-
public function testDenormalizeInvalidDataThrowsException($normalized)
145-
{
146-
$this->expectException(NotNormalizableValueException::class);
147-
$this->normalizer->denormalize($normalized, FlattenException::class);
148-
}
149-
150-
public function provideInvalidNormalizedData(): array
151-
{
152-
return [
153-
'null' => [null],
154-
'string' => ['foo'],
155-
'integer' => [42],
156-
'object' => [new \stdClass()],
157-
];
158-
}
159128
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.