From b91b18fe05ee134330b87a2cf4bae6bf5c73345b Mon Sep 17 00:00:00 2001 From: Patrik Valenta Date: Thu, 16 Apr 2026 22:51:59 +0200 Subject: [PATCH] fix(TestHelper): avoid premature null-init of non-nullable wrapped properties in EntityCreator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit EntityCreator::fill() called $entity->getProperty($key) for every wrapped property to detect IRelationshipCollection. This triggered initProperty() with a null raw value before the user-supplied value from $params was applied, causing NullValueException for non-nullable properties using value wrappers (e.g. DateTimeWrapper on a non-nullable createdAt). Restrict the getProperty() call to collection relationships (ONE_HAS_MANY, MANY_HAS_MANY) — the only ones backed by IRelationshipCollection — using metadata instead of instantiating the wrapper. Non-collection wrapped properties are now initialized directly via setReadOnlyValue() with the supplied value. --- src/TestHelper/EntityCreator.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/TestHelper/EntityCreator.php b/src/TestHelper/EntityCreator.php index 414814669..e2d4580ad 100644 --- a/src/TestHelper/EntityCreator.php +++ b/src/TestHelper/EntityCreator.php @@ -55,7 +55,13 @@ protected function fill(IEntity $entity, array $params): void $value = $this->random($property); } - if ($property->wrapper !== null) { + if ( + $property->relationship !== null + && in_array($property->relationship->type, [ + PropertyRelationshipMetadata::ONE_HAS_MANY, + PropertyRelationshipMetadata::MANY_HAS_MANY, + ], true) + ) { $realProperty = $entity->getProperty($key); if ($realProperty instanceof IRelationshipCollection) { $realProperty->set($value);