From a1602bd91f6cb2bce7f328b89a326cfec2e92d96 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 2 Apr 2015 23:43:16 +0100 Subject: [PATCH] Hydration of fetch-joined results fails when an entity has a default value of `array` for the collection property --- .../EntityWithArrayDefaultArrayValueM2M.php | 15 +++++++++++ .../Tests/Models/Hydration/SimpleEntity.php | 12 +++++++++ .../ORM/Hydration/ObjectHydratorTest.php | 27 +++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 tests/Doctrine/Tests/Models/Hydration/EntityWithArrayDefaultArrayValueM2M.php create mode 100644 tests/Doctrine/Tests/Models/Hydration/SimpleEntity.php diff --git a/tests/Doctrine/Tests/Models/Hydration/EntityWithArrayDefaultArrayValueM2M.php b/tests/Doctrine/Tests/Models/Hydration/EntityWithArrayDefaultArrayValueM2M.php new file mode 100644 index 000000000..8ba57db68 --- /dev/null +++ b/tests/Doctrine/Tests/Models/Hydration/EntityWithArrayDefaultArrayValueM2M.php @@ -0,0 +1,15 @@ +_em); $hydrator->hydrateAll($stmt, $rsm); } + + public function testFetchJoinCollectionValuedAssociationWithDefaultArrayValue() + { + $rsm = new ResultSetMapping; + + $rsm->addEntityResult(EntityWithArrayDefaultArrayValueM2M::CLASSNAME, 'e1', null); + $rsm->addJoinedEntityResult(SimpleEntity::CLASSNAME, 'e2', 'e1', 'collection'); + $rsm->addFieldResult('e1', 'a1__id', 'id'); + $rsm->addFieldResult('e2', 'e2__id', 'id'); + + $result = (new ObjectHydrator($this->_em)) + ->hydrateAll( + new HydratorMockStatement([[ + 'a1__id' => '1', + 'e2__id' => '1', + ]]), + $rsm + ); + + $this->assertCount(1, $result); + $this->assertInstanceOf(EntityWithArrayDefaultArrayValueM2M::CLASSNAME, $result[0]); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[0]->collection); + $this->assertCount(1, $result[0]->collection); + $this->assertInstanceOf(SimpleEntity::CLASSNAME, $result[0]->collection[0]); + } }