8000 Merge branch '5.3' into 5.4 · symfony/symfony@da2c7b8 · GitHub
[go: up one dir, main page]

Skip to content

Commit da2c7b8

Browse files
Merge branch '5.3' into 5.4
* 5.3: [PropertyAccess] Fix Regression in PropertyAccessor::isWritable() [Mime] Allow array as input for RawMessage
2 parents b095293 + d0140f5 commit da2c7b8

File tree

4 files changed

+36
-18
lines changed

4 files changed

+36
-18
lines changed

src/Symfony/Component/Mime/RawMessage.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ public function toString(): string
3333
if (\is_string($this->message)) {
3434
return $this->message;
3535
}
36+
if ($this->message instanceof \Traversable) {
37+
$this->message = iterator_to_array($this->message, false);
38+
}
3639

37-
return $this->message = implode('', iterator_to_array($this->message, false));
40+
return $this->message = implode('', $this->message);
3841
}
3942

4043
public function toIterable(): iterable

src/Symfony/Component/Mime/Tests/RawMessageTest.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,28 @@
1616

1717
class RawMessageTest extends TestCase
1818
{
19-
public function testToString()
19+
/**
20+
* @dataProvider provideMessages
21+
*/
22+
public function testToString($messageParameter)
2023
{
21-
$message = new RawMessage('string');
22-
$this->assertEquals('string', $message->toString());
23-
$this->assertEquals('string', implode('', iterator_to_array($message->toIterable())));
24-
// calling methods more than once work
25-
$this->assertEquals('string', $message->toString());
26-
$this->assertEquals('string', implode('', iterator_to_array($message->toIterable())));
27-
28-
$message = new RawMessage(new \ArrayObject(['some', ' ', 'string']));
24+
$message = new RawMessage($messageParameter);
2925
$this->assertEquals('some string', $message->toString());
3026
$this->assertEquals('some string', implode('', iterator_to_array($message->toIterable())));
3127
// calling methods more than once work
3228
$this->assertEquals('some string', $message->toString());
3329
$this->assertEquals('some string', implode('', iterator_to_array($message->toIterable())));
3430
}
3531

32+
public function provideMessages(): array
33+
{
34+
return [
35+
'string' => ['some string'],
36+
'traversable' => [new \ArrayObject(['some', ' ', 'string'])],
37+
'array' => [['some', ' ', 'string']],
38+
];
39+
}
40+
3641
public function testSerialization()
3742
{
3843
$message = new RawMessage('string');

src/Symfony/Component/PropertyAccess/PropertyAccessor.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,8 @@ public function isWritable($objectOrArray, $propertyPath)
313313
if (!$zval[self::VALUE] instanceof \ArrayAccess && !\is_array($zval[self::VALUE])) {
314314
return false;
315315
}
316-
} else {
317-
if (!$this->isPropertyWritable($zval[self::VALUE], $propertyPath->getElement($i))) {
318-
return false;
319-
}
316+
} elseif (!\is_object($zval[self::VALUE]) || !$this->isPropertyWritable($zval[self::VALUE], $propertyPath->getElement($i))) {
317+
return false;
320318
}
321319

322320
if (\is_object($zval[self::VALUE])) {
@@ -663,10 +661,6 @@ private function getWriteInfo(string $class, string $property, $value): Property
663661
*/
664662
private function isPropertyWritable(object $object, string $property): bool
665663
{
666-
if (!\is_object($object)) {
667-
return false;
668-
}
669-
670664
$mutatorForArray = $this->getWriteInfo(\get_class($object), $property, []);
671665

672666
if (PropertyWriteInfo::TYPE_NONE !== $mutatorForArray->getType() || ($object instanceof \stdClass && property_exists($object, $property))) {

src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorArrayAccessTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ public function getValidPropertyPaths()
3838
];
3939
}
4040

41+
public function getInvalidPropertyPaths()
42+
{
43+
return [
44+
[$this->getContainer(['firstName' => 'Bernhard']), 'firstName', 'Bernhard'],
45+
[$this->getContainer(['person' => $this->getContainer(['firstName' => 'Bernhard'])]), 'person.firstName', 'Bernhard'],
46+
];
47+
}
48+
4149
/**
4250
* @dataProvider getValidPropertyPaths
4351
*/
@@ -83,4 +91,12 @@ public function testIsWritable($collection, $path)
8391
{
8492
$this->assertTrue($this->propertyAccessor->isWritable($collection, $path));
8593
}
94+
95+
/**
96+
* @dataProvider getInvalidPropertyPaths
97+
*/
98+
public function testIsNotWritable($collection, $path)
99+
{
100+
$this->assertFalse($this->propertyAccessor->isWritable($collection, $path));
101+
}
86102
}

0 commit comments

Comments
 (0)
0