1
0
mirror of synced 2025-01-19 06:51:40 +03:00

Merge branch 'hotfix/#1133-better-exception-message-on-missing-embeddable-class-in-metadata'

Close #1133
This commit is contained in:
Marco Pivetta 2015-01-16 19:50:26 +01:00
commit f28654de12
4 changed files with 49 additions and 5 deletions

View File

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

View File

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

View File

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

View File

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