1
0
mirror of synced 2025-02-02 21:41:45 +03:00

added tests on empty values

This commit is contained in:
Full 2017-03-04 15:27:02 +01:00 committed by Marco Pivetta
parent aac523d155
commit 6d40859228
No known key found for this signature in database
GPG Key ID: 4167D3337FD9D629
2 changed files with 50 additions and 1 deletions

View File

@ -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;
}

View File

@ -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');
}
}
}