From 110d773e3cb54f36d6ebca1afdb5803796eaa2a2 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Thu, 1 Apr 2021 11:25:57 +0300 Subject: [PATCH] fix orm entity --- application/Espo/ORM/BaseEntity.php | 4 ++-- tests/unit/Espo/ORM/EntityTest.php | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) 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 = [