diff --git a/application/Espo/ORM/BaseEntity.php b/application/Espo/ORM/BaseEntity.php index 836ff629ab..66d557389d 100644 --- a/application/Espo/ORM/BaseEntity.php +++ b/application/Espo/ORM/BaseEntity.php @@ -1006,7 +1006,7 @@ class BaseEntity implements Entity */ protected function cloneArray(?array $value) : ?array { - if (!$value) { + if ($value === null) { return null; } @@ -1050,7 +1050,7 @@ class BaseEntity implements Entity */ protected function cloneObject(?StdClass $value) : ?StdClass { - if (!$value) { + if ($value === null) { return null; } diff --git a/tests/unit/Espo/ORM/EntityTest.php b/tests/unit/Espo/ORM/EntityTest.php index 595f3f5f11..d86cc395ff 100644 --- a/tests/unit/Espo/ORM/EntityTest.php +++ b/tests/unit/Espo/ORM/EntityTest.php @@ -271,6 +271,24 @@ class EntityTest extends \PHPUnit\Framework\TestCase } + public function testEmptyArray() : void + { + $job = $this->createEntity('Job', Job::class); + + $job->set('array', []); + + $this->assertEquals([], $job->get('array')); + } + + public function testEmptyObject() : void + { + $job = $this->createEntity('Job', Job::class); + + $job->set('object', (object) []); + + $this->assertEquals((object) [], $job->get('object')); + } + public function testCloningArray() : void { $original = [