Skip to content

Commit abf8010

Browse files
Merge branch '4.4' into 5.1
* 4.4: Fix transient tests Fix class resolution in Doctrine EventListenerPass [Serializer] Fix tests marked as incomplete [Translator] fix handling plural for floating numbers fix redis messenger options with dsn Update ConsoleEvents.php allow Doctrine persistence 2 too [Messenger] Fix transporting non-UTF8 payloads by encoding them using base 64 add doctrine/persistence as a dev requirement Exclude non-initialized properties accessed with getters
2 parents 97779ec + c925f4c commit abf8010

File tree

16 files changed

+341
-21
lines changed

16 files changed

+341
-21
lines changed

src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private function addTaggedSubscribers(ContainerBuilder $container, array &$liste
8585

8686
if (!isset($managerDefs[$con])) {
8787
$managerDef = $parentDef = $this->getEventManagerDef($container, $con);
88-
while ($parentDef instanceof ChildDefinition) {
88+
while (!$parentDef->getClass() && $parentDef instanceof ChildDefinition) {
8989
$parentDef = $container->findDefinition($parentDef->getParent());
9090
}
9191
$managerClass = $container->getParameterBag()->resolveValue($parentDef->getClass());

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,6 @@ public function testGetUserWithEmptyContainer()
157157
$controller->getUser();
158158
}
159159

160-
/**
161-
* @param $token
162-
*/
163160
private function getContainerWithTokenStorage($token = null): Container
164161
{
165162
$tokenStorage = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage::class)->getMock();
@@ -484,10 +481,10 @@ public function testGenerateUrl()
484481
public function testRedirect()
485482
{
486483
$controller = $this->createController();
487-
$response = $controller->redirect('http://dunglas.fr', 301);
484+
$response = $controller->redirect('https://dunglas.fr', 301);
488485

489486
$this->assertInstanceOf(\Symfony\Component\HttpFoundation\RedirectResponse::class, $response);
490-
$this->assertSame('http://dunglas.fr', $response->getTargetUrl());
487+
$this->assertSame('https://dunglas.fr', $response->getTargetUrl());
491488
$this->assertSame(301, $response->getStatusCode());
492489
}
493490

@@ -532,7 +529,7 @@ public function testCreateFormBuilder()
532529

533530
public function testGetDoctrine()
534531
{
535-
$doctrine = $this->getMockBuilder(\Doctrine\Persistence\ManagerRegistry::class)->getMock();
532+
$doctrine = $this->createMock(ManagerRegistry::class);
536533

537534
$container = new Container();
538535
$container->set('doctrine', $doctrine);

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"require-dev": {
3636
"doctrine/annotations": "^1.10.4",
3737
"doctrine/cache": "~1.0",
38+
"doctrine/persistence": "^1.3|^2.0",
3839
"symfony/asset": "^5.1",
3940
"symfony/browser-kit": "^4.4|^5.0",
4041
"symfony/console": "^4.4|^5.0",

src/Symfony/Component/Console/ConsoleEvents.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class ConsoleEvents
2121
/**
2222
* The COMMAND event allows you to attach listeners before any command is
2323
* executed by the console. It also allows you to modify the command, input and output
24-
* before they are handled to the command.
24+
* before they are handed to the command.
2525
*
2626
* @Event("Symfony\Component\Console\Event\ConsoleCommandEvent")
2727
*/

src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
use Symfony\Component\HttpKernel\KernelEvents;
2424
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
2525

26+
/**
27+
* @group time-sensitive
28+
*/
2629
class InlineFragmentRendererTest extends TestCase
2730
{
2831
public function testRender()
@@ -253,16 +256,15 @@ public function testIpAddressOfRangedTrustedProxyIsSetAsRemote()
253256
}
254257

255258
/**
256-
* Creates a Kernel expecting a request equals to $request
257-
* Allows delta in comparison in case REQUEST_TIME changed by 1 second.
259+
* Creates a Kernel expecting a request equals to $request.
258260
*/
259261
private function getKernelExpectingRequest(Request $request, $strict = false)
260262
{
261263
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpKernelInterface::class)->getMock();
262264
$kernel
263265
->expects($this->once())
264266
->method('handle')
265-
->with($this->equalTo($request, 1))
267+
->with($request)
266268
->willReturn(new Response('foo'));
267269

268270
return $kernel;

src/Symfony/Component/Messenger/Bridge/Redis/Tests/Transport/ConnectionTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,19 @@ public function testFromDsnWithQueryOptions()
121121
);
122122
}
123123

124+
public function testFromDsnWithMixDsnQueryOptions()
125+
{
126+
$this->assertEquals(
127+
Connection::fromDsn('redis://localhost/queue/group1?serializer=2', ['consumer' => 'specific-consumer']),
128+
Connection::fromDsn('redis://localhost/queue/group1/specific-consumer?serializer=2')
129+
);
130+
131+
$this->assertEquals(
132+
Connection::fromDsn('redis://localhost/queue/group1/consumer1', ['consumer' => 'specific-consumer']),
133+
Connection::fromDsn('redis://localhost/queue/group1/consumer1')
134+
);
135+
}
136+
124137
/**
125138
* @group legacy
126139
*/

src/Symfony/Component/Messenger/Bridge/Redis/Transport/Connection.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ public static function fromDsn(string $dsn, array $redisOptions = [], \Redis $re
105105
throw new InvalidArgumentException(sprintf('The given Redis DSN "%s" is invalid.', $dsn));
106106
}
107107
if (isset($parsedUrl['query'])) {
108-
parse_str($parsedUrl['query'], $redisOptions);
108+
parse_str($parsedUrl['query'], $dsnOptions);
109+
$redisOptions = array_merge($redisOptions, $dsnOptions);
109110
}
110111

111112
self::validateOptions($redisOptions);

src/Symfony/Component/Messenger/Tests/Transport/Serialization/PhpSerializerTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ public function testEncodedSkipsNonEncodeableStamps()
7676
$encoded = $serializer->encode($envelope);
7777
$this->assertStringNotContainsString('DummyPhpSerializerNonSendableStamp', $encoded['body']);
7878
}
79+
80+
public function testNonUtf8IsBase64Encoded()
81+
{
82+
$serializer = new PhpSerializer();
83+
84+
$envelope = new Envelope(new DummyMessage("\xE9"));
85+
86+
$encoded = $serializer->encode($envelope);
87+
$this->assertTrue((bool) preg_match('//u', $encoded['body']), 'Encodes non-UTF8 payloads');
88+
$this->assertEquals($envelope, $serializer->decode($encoded));
89+
}
7990
}
8091

8192
class DummyPhpSerializerNonSendableStamp implements NonSendableStampInterface

src/Symfony/Component/Messenger/Transport/Serialization/PhpSerializer.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public function decode(array $encodedEnvelope): Envelope
2929
throw new MessageDecodingFailedException('Encoded envelope should have at least a "body".');
3030
}
3131

32+
if (false === strpos($encodedEnvelope['body'], '}', -1)) {
33+
$encodedEnvelope['body'] = base64_decode($encodedEnvelope['body']);
34+
}
35+
3236
$serializeEnvelope = stripslashes($encodedEnvelope['body']);
3337

3438
return $this->safelyUnserialize($serializeEnvelope);
@@ -43,6 +47,10 @@ public function encode(Envelope $envelope): array
4347

4448
$body = addslashes(serialize($envelope));
4549

50+
if (!preg_match('//u', $body)) {
51+
$body = base64_encode($body);
52+
}
53+
4654
return [
4755
'body' => $body,
4856
];

src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,19 @@ protected function extractAttributes(object $object, string $format = null, arra
110110
$checkPropertyInitialization = \PHP_VERSION_ID >= 70400;
111111

112112
// properties
113-
foreach ($reflClass->getProperties(\ReflectionProperty::IS_PUBLIC) as $reflProperty) {
114-
if ($checkPropertyInitialization && !$reflProperty->isInitialized($object)) {
115-
continue;
113+
foreach ($reflClass->getProperties() as $reflProperty) {
114+
if ($checkPropertyInitialization) {
115+
$isPublic = $reflProperty->isPublic();
116+
if (!$isPublic) {
117+
$reflProperty->setAccessible(true);
118+
}
119+
if (!$reflProperty->isInitialized($object)) {
120+
unset($attributes[$reflProperty->name]);
121+
continue;
122+
}
123+
if (!$isPublic) {
124+
continue;
125+
}
116126
}
117127

118128
if ($reflProperty->isStatic() || !$this->isAllowedAttribute($object, $reflProperty->name, $format, $context)) {

0 commit comments

Comments
 (0)