Merge pull request #305 from FabioBatSilva/DDC-1470
[DDC-1470] Error messages
This commit is contained in:
commit
6f3ef148a9
@ -23,4 +23,34 @@ class HydrationException extends \Doctrine\ORM\ORMException
|
||||
"discriminator value in a table row."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.3
|
||||
* @param string $entityName
|
||||
* @param string $discrColumnName
|
||||
* @param string $dqlAlias
|
||||
* @return HydrationException
|
||||
*/
|
||||
public static function missingDiscriminatorColumn($entityName, $discrColumnName, $dqlAlias)
|
||||
{
|
||||
return new self(sprintf(
|
||||
'The discriminator column "%s" is missing for "%s" using the DQL alias "%s".',
|
||||
$discrColumnName, $entityName, $dqlAlias
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.3
|
||||
* @param string $entityName
|
||||
* @param string $discrColumnName
|
||||
* @param string $dqlAlias
|
||||
* @return HydrationException
|
||||
*/
|
||||
public static function missingDiscriminatorMetaMappingColumn($entityName, $discrColumnName, $dqlAlias)
|
||||
{
|
||||
return new self(sprintf(
|
||||
'The meta mapping for the discriminator column "%s" is missing for "%s" using the DQL alias "%s".',
|
||||
$discrColumnName, $entityName, $dqlAlias
|
||||
));
|
||||
}
|
||||
}
|
@ -217,8 +217,17 @@ class ObjectHydrator extends AbstractHydrator
|
||||
$className = $this->_rsm->aliasMap[$dqlAlias];
|
||||
|
||||
if (isset($this->_rsm->discriminatorColumns[$dqlAlias])) {
|
||||
|
||||
if ( ! isset($this->_rsm->metaMappings[$this->_rsm->discriminatorColumns[$dqlAlias]])) {
|
||||
throw HydrationException::missingDiscriminatorMetaMappingColumn($className, $this->_rsm->discriminatorColumns[$dqlAlias], $dqlAlias);
|
||||
}
|
||||
|
||||
$discrColumn = $this->_rsm->metaMappings[$this->_rsm->discriminatorColumns[$dqlAlias]];
|
||||
|
||||
if ( ! isset($data[$discrColumn])) {
|
||||
throw HydrationException::missingDiscriminatorColumn($className, $discrColumn, $dqlAlias);
|
||||
}
|
||||
|
||||
if ($data[$discrColumn] === "") {
|
||||
throw HydrationException::emptyDiscriminatorValue($dqlAlias);
|
||||
}
|
||||
|
@ -92,6 +92,10 @@ class SimpleObjectHydrator extends AbstractHydrator
|
||||
if ($this->class->inheritanceType !== ClassMetadata::INHERITANCE_TYPE_NONE) {
|
||||
$discrColumnName = $this->_platform->getSQLResultCasing($this->class->discriminatorColumn['name']);
|
||||
|
||||
if ( ! isset($sqlResult[$discrColumnName])) {
|
||||
throw HydrationException::missingDiscriminatorColumn($entityName, $discrColumnName, key($this->_rsm->aliasMap));
|
||||
}
|
||||
|
||||
if ($sqlResult[$discrColumnName] === '') {
|
||||
throw HydrationException::emptyDiscriminatorValue(key($this->_rsm->aliasMap));
|
||||
}
|
||||
|
@ -1863,4 +1863,69 @@ class ObjectHydratorTest extends HydrationTestCase
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group DDC-1470
|
||||
*
|
||||
* @expectedException \Doctrine\ORM\Internal\Hydration\HydrationException
|
||||
* @expectedExceptionMessage The meta mapping for the discriminator column "c_discr" is missing for "Doctrine\Tests\Models\Company\CompanyFixContract" using the DQL alias "c".
|
||||
*/
|
||||
public function testMissingMetaMappingException()
|
||||
{
|
||||
$rsm = new ResultSetMapping;
|
||||
|
||||
$rsm->addEntityResult('Doctrine\Tests\Models\Company\CompanyFixContract', 'c');
|
||||
$rsm->addJoinedEntityResult('Doctrine\Tests\Models\Company\CompanyEmployee', 'e', 'c', 'salesPerson');
|
||||
|
||||
$rsm->addFieldResult('c', 'c__id', 'id');
|
||||
$rsm->setDiscriminatorColumn('c', 'c_discr');
|
||||
|
||||
$resultSet = array(
|
||||
array(
|
||||
'c__id' => '1',
|
||||
'c_discr' => 'fix',
|
||||
),
|
||||
);
|
||||
|
||||
$stmt = new HydratorMockStatement($resultSet);
|
||||
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
|
||||
$hydrator->hydrateAll($stmt, $rsm);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1470
|
||||
*
|
||||
* @expectedException \Doctrine\ORM\Internal\Hydration\HydrationException
|
||||
* @expectedExceptionMessage The discriminator column "discr" is missing for "Doctrine\Tests\Models\Company\CompanyEmployee" using the DQL alias "e".
|
||||
*/
|
||||
public function testMissingDiscriminatorColumnException()
|
||||
{
|
||||
$rsm = new ResultSetMapping;
|
||||
|
||||
$rsm->addEntityResult('Doctrine\Tests\Models\Company\CompanyFixContract', 'c');
|
||||
$rsm->addJoinedEntityResult('Doctrine\Tests\Models\Company\CompanyEmployee', 'e', 'c', 'salesPerson');
|
||||
|
||||
$rsm->addFieldResult('c', 'c__id', 'id');
|
||||
$rsm->addMetaResult('c', 'c_discr', 'discr');
|
||||
$rsm->setDiscriminatorColumn('c', 'c_discr');
|
||||
|
||||
$rsm->addFieldResult('e', 'e__id', 'id');
|
||||
$rsm->addFieldResult('e', 'e__name', 'name');
|
||||
$rsm->addMetaResult('e ', 'e_discr', 'discr');
|
||||
$rsm->setDiscriminatorColumn('e', 'e_discr');
|
||||
|
||||
$resultSet = array(
|
||||
array(
|
||||
'c__id' => '1',
|
||||
'c_discr' => 'fix',
|
||||
'e__id' => '1',
|
||||
'e__name' => 'Fabio B. Silva'
|
||||
),
|
||||
);
|
||||
|
||||
$stmt = new HydratorMockStatement($resultSet);
|
||||
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
|
||||
$hydrator->hydrateAll($stmt, $rsm);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Hydration;
|
||||
|
||||
use Doctrine\Tests\Mocks\HydratorMockStatement;
|
||||
use Doctrine\ORM\Query\ResultSetMapping;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
class SimpleObjectHydratorTest extends HydrationTestCase
|
||||
{
|
||||
/**
|
||||
* @group DDC-1470
|
||||
*
|
||||
* @expectedException \Doctrine\ORM\Internal\Hydration\HydrationException
|
||||
* @expectedExceptionMessage The discriminator column "discr" is missing for "Doctrine\Tests\Models\Company\CompanyPerson" using the DQL alias "p".
|
||||
*/
|
||||
public function testMissingDiscriminatorColumnException()
|
||||
{
|
||||
$rsm = new ResultSetMapping;
|
||||
$rsm->addEntityResult('Doctrine\Tests\Models\Company\CompanyPerson', 'p');
|
||||
$rsm->addFieldResult('p', 'p__id', 'id');
|
||||
$rsm->addFieldResult('p', 'p__name', 'name');
|
||||
$rsm->addMetaResult('p ', 'discr', 'discr');
|
||||
$rsm->setDiscriminatorColumn('p', 'discr');
|
||||
$resultSet = array(
|
||||
array(
|
||||
'u__id' => '1',
|
||||
'u__name' => 'Fabio B. Silva'
|
||||
),
|
||||
);
|
||||
|
||||
$stmt = new HydratorMockStatement($resultSet);
|
||||
$hydrator = new \Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator($this->_em);
|
||||
$hydrator->hydrateAll($stmt, $rsm);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user