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 f44feb2

Browse filesBrowse files
committed
Merge branch '6.4' into 7.0
* 6.4: (29 commits) fix tests add missing method fix merge fix test fix merge fix test change test to use a real ObjectManager [Mailer] Document the usage of custom headers in Infobip bridge [SecurityBundle] Add `provider` XML attribute to the authenticators it’s missing from [DoctrineBridge] Test reset with a true manager Sync php-cs-fixer config file with 7.2 [HttpClient] Fix parsing SSE [Notifier] Fix thread key in GoogleChat bridge [HttpKernel][Security] Fix accessing session for stateless request [Serializer] Fix `ObjectNormalizer` with property path test handling of special "value" constraint option [PhpUnitBridge] Add missing import [FrameworkBundle] Fix setting default context for certain normalizers [57251] Missing translations for Romanian (ro) [ErrorHandler] Fix rendered exception code highlighting on PHP 8.3 ...
2 parents 1ee25f5 + b3a0478 commit f44feb2
Copy full SHA for f44feb2

File tree

Expand file treeCollapse file tree

7 files changed

+117
-79
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+117
-79
lines changed

‎DependencyInjection/FrameworkExtension.php

Copy file name to clipboardExpand all lines: DependencyInjection/FrameworkExtension.php
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,18 +1917,20 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
19171917
}
19181918

19191919
$arguments = $container->getDefinition('serializer.normalizer.object')->getArguments();
1920-
$context = [];
1920+
$context = $arguments[6] ?? $defaultContext;
19211921

19221922
if (isset($config['circular_reference_handler']) && $config['circular_reference_handler']) {
1923-
$context += ($arguments[6] ?? $defaultContext) + ['circular_reference_handler' => new Reference($config['circular_reference_handler'])];
1923+
$context += ['circular_reference_handler' => new Reference($config['circular_reference_handler'])];
19241924
$container->getDefinition('serializer.normalizer.object')->setArgument(5, null);
19251925
}
19261926

19271927
if ($config['max_depth_handler'] ?? false) {
1928-
$context += ($arguments[6] ?? $defaultContext) + ['max_depth_handler' => new Reference($config['max_depth_handler'])];
1928+
$context += ['max_depth_handler' => new Reference($config['max_depth_handler'])];
19291929
}
19301930

19311931
$container->getDefinition('serializer.normalizer.object')->setArgument(6, $context);
1932+
1933+
$container->getDefinition('serializer.normalizer.property')->setArgument(5, $defaultContext);
19321934
}
19331935

19341936
private function registerPropertyInfoConfiguration(ContainerBuilder $container, PhpFileLoader $loader): void

‎Resources/config/serializer.php

Copy file name to clipboardExpand all lines: Resources/config/serializer.php
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@
140140
service('property_info')->ignoreOnInvalid(),
141141
service('serializer.mapping.class_discriminator_resolver')->ignoreOnInvalid(),
142142
null,
143-
[],
144143
])
145144

146145
->set('serializer.denormalizer.array', ArrayDenormalizer::class)

‎Tests/Functional/AbstractWebTestCase.php

Copy file name to clipboardExpand all lines: Tests/Functional/AbstractWebTestCase.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected static function getKernelClass(): string
5353

5454
protected static function createKernel(array $options = []): KernelInterface
5555
{
56-
$class = self::getKernelClass();
56+
$class = static::getKernelClass();
5757

5858
if (!isset($options['test_case'])) {
5959
throw new \InvalidArgumentException('The option "test_case" must be set.');

‎Tests/Functional/SerializerTest.php

Copy file name to clipboardExpand all lines: Tests/Functional/SerializerTest.php
+47-25Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
1313

1414
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\TranslatableBackedEnum;
15+
use Symfony\Bundle\FrameworkBundle\Tests\Functional\app\AppKernel;
16+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17+
use Symfony\Component\DependencyInjection\ContainerBuilder;
1518

1619
/**
1720
* @author Kévin Dunglas <dunglas@gmail.com>
@@ -35,39 +38,58 @@ public function testDeserializeArrayOfObject()
3538
$this->assertEquals($expected, $result);
3639
}
3740

38-
/**
39-
* @dataProvider provideNormalizersAndEncodersWithDefaultContextOption
40-
*/
41-
public function testNormalizersAndEncodersUseDefaultContextConfigOption(string $normalizerId)
41+
public function testNormalizersAndEncodersUseDefaultContextConfigOption()
4242
{
43-
static::bootKernel(['test_case' => 'Serializer']);
43+
/** @var SerializerKernel $kernel */
44+
$kernel = static::bootKernel(['test_case' => 'Serializer', 'root_config' => 'default_context.yaml']);
45+
46+
foreach ($kernel->normalizersAndEncoders as $normalizerOrEncoderId) {
47+
if (!static::getContainer()->has($normalizerOrEncoderId)) {
48+
continue;
49+
}
50+
51+
$normalizerOrEncoder = static::getContainer()->get($normalizerOrEncoderId);
4452

45-
$normalizer = static::getContainer()->get($normalizerId);
53+
$reflectionObject = new \ReflectionObject($normalizerOrEncoder);
54+
$property = $reflectionObject->getProperty('defaultContext');
4655

47-
$reflectionObject = new \ReflectionObject($normalizer);
48-
$property = $reflectionObject->getProperty('defaultContext');
56+
$defaultContext = $property->getValue($normalizerOrEncoder);
4957

50-
$defaultContext = $property->getValue($normalizer);
58+
self::assertArrayHasKey('fake_context_option', $defaultContext);
59+
self::assertEquals('foo', $defaultContext['fake_context_option']);
60+
}
61+
}
5162

52-
self::assertArrayHasKey('fake_context_option', $defaultContext);
53-
self::assertEquals('foo', $defaultContext['fake_context_option']);
63+
protected static function getKernelClass(): string
64+
{
65+
return SerializerKernel::class;
5466
}
67+
}
68+
69+
class SerializerKernel extends AppKernel implements CompilerPassInterface
70+
{
71+
public $normalizersAndEncoders = [
72+
'serializer.normalizer.property.alias', // Special case as this normalizer isn't tagged
73+
];
5574

56-
public static function provideNormalizersAndEncodersWithDefaultContextOption(): array
75+
public function process(ContainerBuilder $container): void
5776
{
58-
return [
59-
['serializer.normalizer.constraint_violation_list.alias'],
60-
['serializer.normalizer.dateinterval.alias'],
61-
['serializer.normalizer.datetime.alias'],
62-
['serializer.normalizer.json_serializable.alias'],
63-
['serializer.normalizer.problem.alias'],
64-
['serializer.normalizer.uid.alias'],
65-
['serializer.normalizer.translatable.alias'],
66-
['serializer.normalizer.object.alias'],
67-
['serializer.encoder.xml.alias'],
68-
['serializer.encoder.yaml.alias'],
69-
['serializer.encoder.csv.alias'],
70-
];
77+
$services = array_merge(
78+
$container->findTaggedServiceIds('serializer.normalizer'),
79+
$container->findTaggedServiceIds('serializer.encoder')
80+
);
81+
foreach ($services as $serviceId => $attributes) {
82+
$class = $container->getDefinition($serviceId)->getClass();
83+
if (null === $reflectionConstructor = (new \ReflectionClass($class))->getConstructor()) {
84+
continue;
85+
}
86+
foreach ($reflectionConstructor->getParameters() as $reflectionParam) {
87+
if ('array $defaultContext' === $reflectionParam->getType()->getName().' $'.$reflectionParam->getName()) {
88+
$this->normalizersAndEncoders[] = $serviceId.'.alias';
89+
break;
90+
}
91+
}
92+
}
7193
}
7294

7395
public function testSerializeTranslatableBackedEnum()

‎Tests/Functional/app/AppKernel.php

Copy file name to clipboardExpand all lines: Tests/Functional/app/AppKernel.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public function __construct($varDir, $testCase, $rootConfig, $environment, $debu
4949
parent::__construct($environment, $debug);
5050
}
5151

52+
protected function getContainerClass(): string
53+
{
54+
return parent::getContainerClass().substr(md5($this->rootConfig), -16);
55+
}
56+
5257
public function registerBundles(): iterable
5358
{
5459
if (!file_exists($filename = $this->getProjectDir().'/'.$this->testCase.'/bundles.php')) {

‎Tests/Functional/app/Serializer/config.yml

Copy file name to clipboardExpand all lines: Tests/Functional/app/Serializer/config.yml
-49Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,62 +10,13 @@ framework:
1010
max_depth_handler: Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Serializer\MaxDepthHandler
1111
default_context:
1212
enable_max_depth: true
13-
fake_context_option: foo
1413
property_info: { enabled: true }
1514

1615
services:
1716
serializer.alias:
1817
alias: serializer
1918
public: true
2019

21-
serializer.normalizer.constraint_violation_list.alias:
22-
alias: serializer.normalizer.constraint_violation_list
23-
public: true
24-
25-
serializer.normalizer.dateinterval.alias:
26-
alias: serializer.normalizer.dateinterval
27-
public: true
28-
29-
serializer.normalizer.datetime.alias:
30-
alias: serializer.normalizer.datetime
31-
public: true
32-
33-
serializer.normalizer.json_serializable.alias:
34-
alias: serializer.normalizer.json_serializable
35-
public: true
36-
37-
serializer.normalizer.problem.alias:
38-
alias: serializer.normalizer.problem
39-
public: true
40-
41-
serializer.normalizer.uid.alias:
42-
alias: serializer.normalizer.uid
43-
public: true
44-
45-
serializer.normalizer.translatable.alias:
46-
alias: serializer.normalizer.translatable
47-
public: true
48-
49-
serializer.normalizer.property.alias:
50-
alias: serializer.normalizer.property
51-
public: true
52-
53-
serializer.normalizer.object.alias:
54-
alias: serializer.normalizer.object
55-
public: true
56-
57-
serializer.encoder.xml.alias:
58-
alias: serializer.encoder.xml
59-
public: true
60-
61-
serializer.encoder.yaml.alias:
62-
alias: serializer.encoder.yaml
63-
public: true
64-
65-
serializer.encoder.csv.alias:
66-
alias: serializer.encoder.csv
67-
public: true
68-
6920
Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Serializer\CircularReferenceHandler: ~
7021

7122
Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Serializer\MaxDepthHandler: ~
+59Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
imports:
2+
- { resource: ../config/default.yml }
3+
4+
framework:
5+
serializer:
6+
enabled: true
7+
circular_reference_handler: ~ # This must be null
8+
max_depth_handler: ~ # This must be null
9+
default_context:
10+
fake_context_option: foo
11+
12+
services:
13+
serializer.normalizer.constraint_violation_list.alias:
14+
alias: serializer.normalizer.constraint_violation_list
15+
public: true
16+
17+
serializer.normalizer.dateinterval.alias:
18+
alias: serializer.normalizer.dateinterval
19+
public: true
20+
21+
serializer.normalizer.datetime.alias:
22+
alias: serializer.normalizer.datetime
23+
public: true
24+
25+
serializer.normalizer.json_serializable.alias:
26+
alias: serializer.normalizer.json_serializable
27+
public: true
28+
29+
serializer.normalizer.object.alias:
30+
alias: serializer.normalizer.object
31+
public: true
32+
33+
serializer.normalizer.problem.alias:
34+
alias: serializer.normalizer.problem
35+
public: true
36+
37+
serializer.normalizer.property.alias:
38+
alias: serializer.normalizer.property
39+
public: true
40+
41+
serializer.normalizer.uid.alias:
42+
alias: serializer.normalizer.uid
43+
public: true
44+
45+
serializer.encoder.csv.alias:
46+
alias: serializer.encoder.csv
47+
public: true
48+
49+
serializer.encoder.json.alias:
50+
alias: serializer.encoder.json
51+
public: true
52+
53+
serializer.encoder.xml.alias:
54+
alias: serializer.encoder.xml
55+
public: true
56+
57+
serializer.encoder.yaml.alias:
58+
alias: serializer.encoder.yaml
59+
public: true

0 commit comments

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