Skip to content

Commit

Permalink
#1133 DDC-3305 - test case with embeddable without referenced embedda…
Browse files Browse the repository at this point in the history
…ble class
  • Loading branch information
Ocramius committed Jan 16, 2015
1 parent 705a7d2 commit 7e4dab1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
Expand Up @@ -170,7 +170,7 @@ protected function doLoadMetadata($class, $parent, $rootEntityFound, array $nonS
continue;
}

if (!isset($embeddableClass['class'])) {
if (! (isset($embeddableClass['class']) && $embeddableClass['class'])) {
throw MappingException::missingEmbeddedClass($property);
}

Expand Down
8 changes: 6 additions & 2 deletions lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
Expand Up @@ -3166,11 +3166,15 @@ public function getAssociationsByTargetClass($targetClass)
}

/**
* @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;
}
Expand Down
32 changes: 29 additions & 3 deletions tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php
Expand Up @@ -29,7 +29,7 @@ public function testGetMetadataForSingleClass()
$cm1 = $this->_createValidClassMetadata();

// SUT
$cmf = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
$cmf = new ClassMetadataFactory();
$cmf->setEntityManager($entityManager);
$cmf->setMetadataFor($cm1->name, $cm1);

Expand Down Expand Up @@ -375,10 +375,35 @@ public function testAcceptsEntityManagerInterfaceInstances()
// 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();
Expand All @@ -388,7 +413,7 @@ protected function newClassMetadataInstance($className)
{
$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];
}
Expand All @@ -410,6 +435,7 @@ class TestEntity1
private $name;
private $other;
private $association;
private $embedded;
}

class CustomIdGenerator extends AbstractIdGenerator
Expand Down

0 comments on commit 7e4dab1

Please sign in to comment.