Skip to content

Commit 6a4d229

Browse files
committed
Merge branch '5.4' into 6.4
* 5.4: (21 commits) [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 [String] Fix symfony#54611 pluralization of -on ending words + singularization of -a ending foreign words [Validator] [UniqueValidator] Use correct variable as parameter in (custom) error message [Messenger] Comply with Amazon SQS requirements for message body fix cssColor HSLA test dataProvider properly handle invalid data for false/true types chore: upgrade class doc add space in error message [Messenger] [Amqp] Handle AMQPConnectionException when publishing a message. ...
2 parents bab19b6 + e79eea1 commit 6a4d229

File tree

53 files changed

+560
-236
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+560
-236
lines changed

.php-cs-fixer.dist.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,17 @@
2929
'@Symfony' => true,
3030
'@Symfony:risky' => true,
3131
'protected_to_private' => false,
32-
'native_constant_invocation' => ['strict' => false],
3332
'no_superfluous_phpdoc_tags' => [
3433
'remove_inheritdoc' => true,
3534
'allow_unused_params' => true, // for future-ready params, to be replaced with https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7377
3635
],
37-
'nullable_type_declaration_for_default_null_value' => true,
3836
'header_comment' => ['header' => $fileHeaderComment],
37+
// TODO: Remove once the "compiler_optimized" set includes "sprintf"
38+
'native_function_invocation' => ['include' => ['@compiler_optimized', 'sprintf'], 'scope' => 'namespaced', 'strict' => true],
39+
'nullable_type_declaration' => true,
40+
'nullable_type_declaration_for_default_null_value' => true,
3941
'modernize_strpos' => true,
4042
'get_class_to_class_keyword' => true,
41-
'nullable_type_declaration' => true,
4243
])
4344
->setRiskyAllowed(true)
4445
->setFinder(
@@ -47,11 +48,6 @@
4748
->append([__FILE__])
4849
->notPath('#/Fixtures/#')
4950
->exclude([
50-
// directories containing files with content that is autogenerated by `var_export`, which breaks CS in output code
51-
// fixture templates
52-
'Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Resources/Custom',
53-
// resource templates
54-
'Symfony/Bundle/FrameworkBundle/Resources/views/Form',
5551
// explicit trigger_error tests
5652
'Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/',
5753
'Symfony/Component/Intl/Resources/data/',
@@ -65,10 +61,6 @@
6561
->notPath('#Symfony/Bridge/PhpUnit/.*Legacy#')
6662
// file content autogenerated by `var_export`
6763
->notPath('Symfony/Component/Translation/Tests/Fixtures/resources.php')
68-
// file content autogenerated by `VarExporter::export`
69-
->notPath('Symfony/Component/Serializer/Tests/Fixtures/serializer.class.metadata.php')
70-
// test template
71-
->notPath('Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Resources/Custom/_name_entry_label.html.php')
7264
// explicit trigger_error tests
7365
->notPath('Symfony/Component/ErrorHandler/Tests/DebugClassLoaderTest.php')
7466
// stop removing spaces on the end of the line in strings
@@ -79,6 +71,10 @@
7971
->notPath('Symfony/Component/Cache/Traits/Redis6Proxy.php')
8072
->notPath('Symfony/Component/Cache/Traits/RedisCluster5Proxy.php')
8173
->notPath('Symfony/Component/Cache/Traits/RedisCluster6Proxy.php')
74+
// svg
75+
->notPath('Symfony/Component/ErrorHandler/Resources/assets/images/symfony-ghost.svg.php')
76+
// HTML templates
77+
->notPath('#Symfony/.*\.html\.php#')
8278
)
8379
->setCacheFile('.php-cs-fixer.cache')
8480
;
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace Symfony\Bridge\Doctrine\Tests\Fixtures;
4+
5+
use Doctrine\Persistence\Mapping\ClassMetadata;
6+
use Doctrine\Persistence\Mapping\ClassMetadataFactory;
7+
use Doctrine\Persistence\ObjectManager;
8+
use Doctrine\Persistence\ObjectRepository;
9+
10+
class DummyManager implements ObjectManager
11+
{
12+
public $bar;
13+
14+
public function find($className, $id): ?object
15+
{
16+
}
17+
18+
public function persist($object): void
19+
{
20+
}
21+
22+
public function remove($object): void
23+
{
24+
}
25+
26+
public function merge($object)
27+
{
28+
}
29+
30+
public function clear($objectName = null): void
31+
{
32+
}
33+
34+
public function detach($object): void
35+
{
36+
}
37+
38+
public function refresh($object): void
39+
{
40+
}
41+
42+
public function flush(): void
43+
{
44+
}
45+
46+
public function getRepository($className): ObjectRepository
47+
{
48+
}
49+
50+
public function getClassMetadata($className): ClassMetadata
51+
{
52+
}
53+
54+
public function getMetadataFactory(): ClassMetadataFactory
55+
{
56+
}
57+
58+
public function initializeObject($obj): void
59+
{
60+
}
61+
62+
public function contains($object): bool
63+
{
64+
}
65+
66+
public function isUninitializedObject($value): bool
67+
{
68+
}
69+
}

src/Symfony/Bridge/Doctrine/Tests/ManagerRegistryTest.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Tests;
1313

14+
use Doctrine\Persistence\ObjectManager;
1415
use PHPUnit\Framework\TestCase;
16+
use ProxyManager\Proxy\LazyLoadingInterface;
17+
use ProxyManager\Proxy\ValueHolderInterface;
18+
use Symfony\Bridge\Doctrine\ManagerRegistry;
19+
use Symfony\Bridge\Doctrine\Tests\Fixtures\DummyManager;
20+
use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper;
1521
use Symfony\Component\DependencyInjection\ContainerBuilder;
1622
use Symfony\Component\DependencyInjection\ContainerInterface;
1723
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
@@ -24,8 +30,8 @@ public static function setUpBeforeClass(): void
2430
{
2531
$container = new ContainerBuilder();
2632

27-
$container->register('foo', \stdClass::class)->setPublic(true);
28-
$container->getDefinition('foo')->setLazy(true)->addTag('proxy', ['interface' => \stdClass::class]);
33+
$container->register('foo', DummyManager::class)->setPublic(true);
34+
$container->getDefinition('foo')->setLazy(true)->addTag('proxy', ['interface' => ObjectManager::class]);
2935
$container->compile();
3036

3137
$dumper = new PhpDumper($container);
@@ -46,8 +52,8 @@ public function testResetService()
4652
$registry->resetManager();
4753

4854
$this->assertSame($foo, $container->get('foo'));
49-
$this->assertInstanceOf(\stdClass::class, $foo);
50-
$this->assertFalse(property_exists($foo, 'bar'));
55+
$this->assertInstanceOf(ObjectManager::class, $foo);
56+
$this->assertFalse(isset($foo->bar));
5157
}
5258

5359
/**
@@ -79,7 +85,7 @@ public function testResetServiceWillNotNestFurtherLazyServicesWithinEachOther()
7985

8086
$service = $container->get('foo');
8187

82-
self::assertInstanceOf(\stdClass::class, $service);
88+
self::assertInstanceOf(ObjectManager::class, $service);
8389
self::assertInstanceOf(LazyObjectInterface::class, $service);
8490
self::assertFalse($service->isLazyObjectInitialized());
8591

@@ -92,7 +98,7 @@ public function testResetServiceWillNotNestFurtherLazyServicesWithinEachOther()
9298
$service->initializeLazyObject();
9399

94100
$wrappedValue = $service->initializeLazyObject();
95-
self::assertInstanceOf(\stdClass::class, $wrappedValue);
101+
self::assertInstanceOf(DummyManager::class, $wrappedValue);
96102
self::assertNotInstanceOf(LazyObjectInterface::class, $wrappedValue);
97103
}
98104

@@ -104,10 +110,10 @@ private function dumpLazyServiceDoctrineBridgeContainerAsFiles()
104110

105111
$container = new ContainerBuilder();
106112

107-
$container->register('foo', \stdClass::class)
113+
$container->register('foo', DummyManager::class)
108114
->setPublic(true)
109115
->setLazy(true)
110-
->addTag('proxy', ['interface' => \stdClass::class]);
116+
->addTag('proxy', ['interface' => ObjectManager::class]);
111117
$container->compile();
112118

113119
$fileSystem = new Filesystem();

src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ public function testAttributeWithGroupsAndPaylod()
6060
self::assertSame('some attached data', $constraint->payload);
6161
self::assertSame(['some_group'], $constraint->groups);
6262
}
63+
64+
public function testValueOptionConfiguresFields()
65+
{
66+
$constraint = new UniqueEntity(['value' => 'email']);
67+
68+
$this->assertSame('email', $constraint->fields);
69+
}
6370
}
6471

6572
#[UniqueEntity(['email'], message: 'myMessage')]

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bridge\PhpUnit;
1313

14+
use PHPUnit\Framework\TestCase;
1415
use PHPUnit\Framework\TestResult;
1516
use PHPUnit\Runner\ErrorHandler;
1617
use PHPUnit\Util\Error\Handler;

src/Symfony/Bridge/Twig/Extension/CodeExtension.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ public function fileExcerpt(string $file, int $line, int $srcContext = 3): ?stri
128128
if (\PHP_VERSION_ID >= 80300) {
129129
// remove main pre/code tags
130130
$code = preg_replace('#^<pre.*?>\s*<code.*?>(.*)</code>\s*</pre>#s', '\\1', $code);
131-
// split multiline code tags
132-
$code = preg_replace_callback('#<code ([^>]++)>((?:[^<]*+\\n)++[^<]*+)</code>#', fn ($m) => "<code $m[1]>".str_replace("\n", "</code>\n<code $m[1]>", $m[2]).'</code>', $code);
133-
// Convert spaces to html entities to preserve indentation when rendered
134-
$code = str_replace(' ', '&nbsp;', $code);
131+
// split multiline span tags
132+
$code = preg_replace_callback('#<span ([^>]++)>((?:[^<\\n]*+\\n)++[^<]*+)</span>#', function ($m) {
133+
return "<span $m[1]>".str_replace("\n", "</span>\n<span $m[1]>", $m[2]).'</span>';
134+
}, $code);
135135
$content = explode("\n", $code);
136136
} else {
137137
// remove main code/span tags

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,18 +2001,20 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
20012001
}
20022002

20032003
$arguments = $container->getDefinition('serializer.normalizer.object')->getArguments();
2004-
$context = [];
2004+
$context = $arguments[6] ?? $defaultContext;
20052005

20062006
if (isset($config['circular_reference_handler']) && $config['circular_reference_handler']) {
2007-
$context += ($arguments[6] ?? $defaultContext) + ['circular_reference_handler' => new Reference($config['circular_reference_handler'])];
2007+
$context += ['circular_reference_handler' => new Reference($config['circular_reference_handler'])];
20082008
$container->getDefinition('serializer.normalizer.object')->setArgument(5, null);
20092009
}
20102010

20112011
if ($config['max_depth_handler'] ?? false) {
2012-
$context += ($arguments[6] ?? $defaultContext) + ['max_depth_handler' => new Reference($config['max_depth_handler'])];
2012+
$context += ['max_depth_handler' => new Reference($config['max_depth_handler'])];
20132013
}
20142014

20152015
$container->getDefinition('serializer.normalizer.object')->setArgument(6, $context);
2016+
2017+
$container->getDefinition('serializer.normalizer.property')->setArgument(5, $defaultContext);
20162018
}
20172019

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

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@
144144
service('property_info')->ignoreOnInvalid(),
145145
service('serializer.mapping.class_discriminator_resolver')->ignoreOnInvalid(),
146146
null,
147-
[],
148147
])
149148

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

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AbstractWebTestCase.php

Lines 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.');

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

Lines changed: 43 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 <[email protected]>
@@ -35,39 +38,54 @@ 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']);
4445

45-
$normalizer = static::getContainer()->get($normalizerId);
46+
foreach ($kernel->normalizersAndEncoders as $normalizerOrEncoderId) {
47+
$normalizerOrEncoder = static::getContainer()->get($normalizerOrEncoderId);
4648

47-
$reflectionObject = new \ReflectionObject($normalizer);
48-
$property = $reflectionObject->getProperty('defaultContext');
49+
$reflectionObject = new \ReflectionObject($normalizerOrEncoder);
50+
$property = $reflectionObject->getProperty('defaultContext');
4951

50-
$defaultContext = $property->getValue($normalizer);
52+
$defaultContext = $property->getValue($normalizerOrEncoder);
5153

52-
self::assertArrayHasKey('fake_context_option', $defaultContext);
53-
self::assertEquals('foo', $defaultContext['fake_context_option']);
54+
self::assertArrayHasKey('fake_context_option', $defaultContext);
55+
self::assertEquals('foo', $defaultContext['fake_context_option']);
56+
}
5457
}
5558

56-
public static function provideNormalizersAndEncodersWithDefaultContextOption(): array
59+
protected static function getKernelClass(): string
60+
{
61+
return SerializerKernel::class;
62+
}
63+
}
64+
65+
class SerializerKernel extends AppKernel implements CompilerPassInterface
66+
{
67+
public $normalizersAndEncoders = [
68+
'serializer.normalizer.property.alias', // Special case as this normalizer isn't tagged
69+
];
70+
71+
public function process(ContainerBuilder $container)
5772
{
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-
];
73+
$services = array_merge(
74+
$container->findTaggedServiceIds('serializer.normalizer'),
75+
$container->findTaggedServiceIds('serializer.encoder')
76+
);
77+
foreach ($services as $serviceId => $attributes) {
78+
$class = $container->getDefinition($serviceId)->getClass();
79+
if (null === $reflectionConstructor = (new \ReflectionClass($class))->getConstructor()) {
80+
continue;
81+
}
82+
foreach ($reflectionConstructor->getParameters() as $reflectionParam) {
83+
if ('array $defaultContext' === $reflectionParam->getType()->getName().' $'.$reflectionParam->getName()) {
84+
$this->normalizersAndEncoders[] = $serviceId.'.alias';
85+
break;
86+
}
87+
}
88+
}
7189
}
7290

7391
public function testSerializeTranslatableBackedEnum()

0 commit comments

Comments
 (0)