From 6d40859228d64ef6f2c5477042182bfd8bfd110d Mon Sep 17 00:00:00 2001 From: Full Date: Sat, 4 Mar 2017 15:27:02 +0100 Subject: [PATCH] added tests on empty values --- .../Internal/Hydration/AbstractHydrator.php | 6 ++- .../ORM/Functional/Ticket/DDC6303Test.php | 45 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index 04e98c72e..7490e3e4f 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -294,10 +294,14 @@ abstract class AbstractHydrator $dqlAlias = $cacheKeyInfo['dqlAlias']; $type = $cacheKeyInfo['type']; + var_dump($dqlAlias); + var_dump($cacheKeyInfo); + echo "\n\n\n"; + // in an inheritance hierarchy the same field could be defined several times. // We overwrite this value so long we don't have a non-null value, that value we keep. // Per definition it cannot be that a field is defined several times and has several values. - if (isset($rowData['data'][$dqlAlias][$fieldName])) { + if (!empty($rowData['data'][$dqlAlias][$fieldName])) { break; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php index 96dd32f9b..d967b3b7f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC6303Test.php @@ -53,4 +53,49 @@ class DDC6303Test extends \Doctrine\Tests\OrmFunctionalTestCase } } } + + public function testEmptyValuesInJoinedInheritance() + { + $contractStringEmptyData = ''; + $contractStringZeroData = 0; + + $contractArrayEmptyData = []; + + $contractStringEmpty = new DDC6303ContractA(); + $contractStringEmpty->originalData = $contractStringEmptyData; + + $contractStringZero = new DDC6303ContractA(); + $contractStringZero->originalData = $contractStringZeroData; + + $contractArrayEmpty = new DDC6303ContractB(); + $contractArrayEmpty->originalData = $contractArrayEmptyData; + + $this->_em->persist($contractStringZero); + $this->_em->persist($contractStringEmpty); + $this->_em->persist($contractArrayEmpty); + + $this->_em->flush(); + + // clear entity manager so that $repository->find actually fetches them and uses the hydrator + // instead of just returning the existing managed entities + $this->_em->clear(); + + $repository = $this->_em->getRepository(DDC6303Contract::class); + $dataMap = [ + $contractStringZero->id => $contractStringZeroData, + $contractStringEmpty->id => $contractStringEmptyData, + $contractArrayEmpty->id => $contractArrayEmptyData, + ]; + + $contracts = $repository->createQueryBuilder('p') + ->where('p.id IN(:ids)') + ->setParameter('ids', array_keys($dataMap)) + ->getQuery()->getResult(); + + + + foreach( $contracts as $contract ){ + static::assertEquals($contract->originalData, $dataMap[$contract->id], 'contract ' . get_class($contract) . ' not equals to original'); + } + } }