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 db6ab74

Browse filesBrowse files
wuchen90nicolas-grekas
authored andcommitted
[FrameworkBundle] Fix passing serializer.default_context option to normalizers
1 parent c542a03 commit db6ab74
Copy full SHA for db6ab74

File tree

3 files changed

+25
-3
lines changed
Filter options

3 files changed

+25
-3
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.php
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@
7878

7979
// Normalizer
8080
->set('serializer.normalizer.constraint_violation_list', ConstraintViolationListNormalizer::class)
81-
->args([[], service('serializer.name_converter.metadata_aware')])
81+
->args([1 => service('serializer.name_converter.metadata_aware')])
82+
->autowire(true)
8283
->tag('serializer.normalizer', ['priority' => -915])
8384

8485
->set('serializer.normalizer.mime_message', MimeMessageNormalizer::class)
@@ -124,7 +125,6 @@
124125
service('property_info')->ignoreOnInvalid(),
125126
service('serializer.mapping.class_discriminator_resolver')->ignoreOnInvalid(),
126127
null,
127-
[],
128128
])
129129
->tag('serializer.normalizer', ['priority' => -1000])
130130

@@ -137,7 +137,6 @@
137137
service('property_info')->ignoreOnInvalid(),
138138
service('serializer.mapping.class_discriminator_resolver')->ignoreOnInvalid(),
139139
null,
140-
[],
141140
])
142141

143142
->alias(PropertyNormalizer::class, 'serializer.normalizer.property')

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SerializerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SerializerTest.php
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ public function testDeserializeArrayOfObject()
3232

3333
$this->assertEquals($expected, $result);
3434
}
35+
36+
public function testObjectNormalizerUsesDefaultContextConfigOption()
37+
{
38+
static::bootKernel(['test_case' => 'Serializer']);
39+
40+
$serializer = static::getContainer()->get('serializer.normalizer.object.alias');
41+
42+
$reflectionObject = new \ReflectionObject($serializer);
43+
$property = $reflectionObject->getProperty('defaultContext');
44+
$property->setAccessible(true);
45+
46+
$defaultContext = $property->getValue($serializer);
47+
48+
self::assertArrayHasKey('fake_context_option', $defaultContext);
49+
self::assertEquals('foo', $defaultContext['fake_context_option']);
50+
}
3551
}
3652

3753
class Foo

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Serializer/config.yml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Serializer/config.yml
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@ framework:
66
enabled: true
77
default_context:
88
enable_max_depth: true
9+
# The option below is used in \Symfony\Bundle\FrameworkBundle\Tests\Functional\SerializerTest::testObjectNormalizerUsesDefaultContextConfigOption
10+
# to assert that the `default_context` is taken into account in serializers
11+
fake_context_option: foo
912
property_info: { enabled: true }
1013

1114
services:
1215
serializer.alias:
1316
alias: serializer
1417
public: true
18+
19+
serializer.normalizer.object.alias:
20+
alias: serializer.normalizer.object
21+
public: true

0 commit comments

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