Skip to content

Commit a2f56d7

Browse files
committed
Ignore values assigned to initialized readonly properties
1 parent c51ba3c commit a2f56d7

File tree

2 files changed

+3
-15
lines changed

2 files changed

+3
-15
lines changed

src/Mapping/ReflectionReadonlyProperty.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@
55
namespace Doctrine\ORM\Mapping;
66

77
use InvalidArgumentException;
8-
use LogicException;
98
use ReflectionProperty;
109

11-
use function assert;
1210
use function func_get_args;
1311
use function func_num_args;
14-
use function is_object;
15-
use function sprintf;
1612

1713
/** @internal */
1814
final class ReflectionReadonlyProperty extends ReflectionProperty
@@ -36,14 +32,6 @@ public function setValue(mixed $objectOrValue, mixed $value = null): void
3632
{
3733
if (func_num_args() < 2 || $objectOrValue === null || ! $this->isInitialized($objectOrValue)) {
3834
$this->wrappedProperty->setValue(...func_get_args());
39-
40-
return;
41-
}
42-
43-
assert(is_object($objectOrValue));
44-
45-
if (parent::getValue($objectOrValue) !== $value) {
46-
throw new LogicException(sprintf('Attempting to change readonly property %s::$%s.', $this->class, $this->name));
4735
}
4836
}
4937
}

tests/Tests/ORM/Mapping/ReflectionReadonlyPropertyTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Doctrine\Tests\Models\CMS\CmsTag;
99
use Doctrine\Tests\Models\ReadonlyProperties\Author;
1010
use InvalidArgumentException;
11-
use LogicException;
1211
use PHPUnit\Framework\TestCase;
1312
use ReflectionProperty;
1413

@@ -44,9 +43,10 @@ public function testSecondWriteWithDifferentValue(): void
4443

4544
$reflection->setValue($author, 'John Doe');
4645

47-
$this->expectException(LogicException::class);
48-
$this->expectExceptionMessage('Attempting to change readonly property Doctrine\Tests\Models\ReadonlyProperties\Author::$name.');
4946
$reflection->setValue($author, 'Jane Doe');
47+
48+
self::assertSame('John Doe', $wrappedReflection->getValue($author));
49+
self::assertSame('John Doe', $reflection->getValue($author));
5050
}
5151

5252
public function testNonReadonlyPropertiesAreForbidden(): void

0 commit comments

Comments
 (0)