From da41161d73e5fca87b3659219eda56026d95a515 Mon Sep 17 00:00:00 2001
From: Carl Vuorinen <carl.vuorinen@gmail.com>
Date: Thu, 8 Sep 2016 13:50:28 +0300
Subject: [PATCH] Add unit test for SimpleObjectHydrator

---
 .../Hydration/SimpleObjectHydratorTest.php    | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/tests/Doctrine/Tests/ORM/Hydration/SimpleObjectHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/SimpleObjectHydratorTest.php
index 459ce9ba1..9878728f2 100644
--- a/tests/Doctrine/Tests/ORM/Hydration/SimpleObjectHydratorTest.php
+++ b/tests/Doctrine/Tests/ORM/Hydration/SimpleObjectHydratorTest.php
@@ -86,4 +86,34 @@ class SimpleObjectHydratorTest extends HydrationTestCase
         $hydrator   = new \Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator($this->_em);
         $hydrator->hydrateAll($stmt, $rsm);
     }
+
+    /**
+     * @group issue-5989
+     */
+    public function testNullValueShouldNotOverwriteFieldWithSameNameInJoinedInheritance()
+    {
+        $rsm = new ResultSetMapping;
+        $rsm->addEntityResult('Doctrine\Tests\Models\Issue5989\Issue5989Person', 'p');
+        $rsm->addFieldResult('p', 'p__id', 'id');
+        $rsm->addFieldResult('p', 'm__tags', 'tags', 'Doctrine\Tests\Models\Issue5989\Issue5989Manager');
+        $rsm->addFieldResult('p', 'e__tags', 'tags', 'Doctrine\Tests\Models\Issue5989\Issue5989Employee');
+        $rsm->addMetaResult('p', 'discr', 'discr', false, 'string');
+        $resultSet = array(
+            array(
+                'p__id'   => '1',
+                'm__tags' => 'tag1,tag2',
+                'e__tags' => null,
+                'discr'   => 'manager'
+            ),
+        );
+
+        $expectedEntity = new \Doctrine\Tests\Models\Issue5989\Issue5989Manager();
+        $expectedEntity->id = 1;
+        $expectedEntity->tags = ['tag1', 'tag2'];
+
+        $stmt       = new HydratorMockStatement($resultSet);
+        $hydrator   = new \Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator($this->_em);
+        $result = $hydrator->hydrateAll($stmt, $rsm);
+        $this->assertEquals($result[0], $expectedEntity);
+    }
 }