Merge branch 'hotfix/#1133-better-exception-message-on-missing-embeddable-class-in-metadata'
Close #1133
This commit is contained in:
commit
f28654de12
@ -170,6 +170,10 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! (isset($embeddableClass['class']) && $embeddableClass['class'])) {
|
||||
throw MappingException::missingEmbeddedClass($property);
|
||||
}
|
||||
|
||||
if (isset($this->embeddablesActiveNesting[$embeddableClass['class']])) {
|
||||
throw MappingException::infiniteEmbeddableNesting($class->name, $property);
|
||||
}
|
||||
|
@ -3166,11 +3166,15 @@ class ClassMetadataInfo implements ClassMetadata
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $className
|
||||
* @return string
|
||||
* @param string|null $className
|
||||
* @return string|null null if the input value is null
|
||||
*/
|
||||
public function fullyQualifiedClassName($className)
|
||||
{
|
||||
if (empty($className)) {
|
||||
return $className;
|
||||
}
|
||||
|
||||
if ($className !== null && strpos($className, '\\') === false && strlen($this->namespace) > 0) {
|
||||
return $this->namespace . '\\' . $className;
|
||||
}
|
||||
|
@ -105,6 +105,16 @@ class MappingException extends \Doctrine\ORM\ORMException
|
||||
return new self("The association mapping '$fieldName' misses the 'sourceEntity' attribute.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $fieldName
|
||||
*
|
||||
* @return MappingException
|
||||
*/
|
||||
public static function missingEmbeddedClass($fieldName)
|
||||
{
|
||||
return new self("The embed mapping '$fieldName' misses the 'class' attribute.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $entityName
|
||||
* @param string $fileName
|
||||
|
@ -29,7 +29,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase
|
||||
$cm1 = $this->_createValidClassMetadata();
|
||||
|
||||
// SUT
|
||||
$cmf = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
|
||||
$cmf = new ClassMetadataFactory();
|
||||
$cmf->setEntityManager($entityManager);
|
||||
$cmf->setMetadataFor($cm1->name, $cm1);
|
||||
|
||||
@ -375,10 +375,35 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase
|
||||
// not really the cleanest way to check it, but we won't add a getter to the CMF just for the sake of testing.
|
||||
$this->assertAttributeSame($entityManager, 'em', $classMetadataFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-3305
|
||||
*/
|
||||
public function testRejectsEmbeddableWithoutValidClassName()
|
||||
{
|
||||
$metadata = $this->_createValidClassMetadata();
|
||||
|
||||
$metadata->mapEmbedded(array(
|
||||
'fieldName' => 'embedded',
|
||||
'class' => '',
|
||||
'columnPrefix' => false,
|
||||
));
|
||||
|
||||
$cmf = $this->_createTestFactory();
|
||||
|
||||
$cmf->setMetadataForClass($metadata->name, $metadata);
|
||||
|
||||
$this->setExpectedException(
|
||||
'Doctrine\ORM\Mapping\MappingException',
|
||||
'The embed mapping \'embedded\' misses the \'class\' attribute.'
|
||||
);
|
||||
|
||||
$cmf->getMetadataFor($metadata->name);
|
||||
}
|
||||
}
|
||||
|
||||
/* Test subject class with overridden factory method for mocking purposes */
|
||||
class ClassMetadataFactoryTestSubject extends \Doctrine\ORM\Mapping\ClassMetadataFactory
|
||||
class ClassMetadataFactoryTestSubject extends ClassMetadataFactory
|
||||
{
|
||||
private $mockMetadata = array();
|
||||
private $requestedClasses = array();
|
||||
@ -388,7 +413,7 @@ class ClassMetadataFactoryTestSubject extends \Doctrine\ORM\Mapping\ClassMetadat
|
||||
{
|
||||
$this->requestedClasses[] = $className;
|
||||
if ( ! isset($this->mockMetadata[$className])) {
|
||||
throw new InvalidArgumentException("No mock metadata found for class $className.");
|
||||
throw new \InvalidArgumentException("No mock metadata found for class $className.");
|
||||
}
|
||||
return $this->mockMetadata[$className];
|
||||
}
|
||||
@ -410,6 +435,7 @@ class TestEntity1
|
||||
private $name;
|
||||
private $other;
|
||||
private $association;
|
||||
private $embedded;
|
||||
}
|
||||
|
||||
class CustomIdGenerator extends AbstractIdGenerator
|
||||
|
Loading…
x
Reference in New Issue
Block a user