1
0
mirror of synced 2024-12-13 22:56:04 +03:00

Throw exception if target entity is not found.

This commit is contained in:
Benjamin Eberlei 2011-10-22 11:28:07 +02:00
parent dba8360166
commit 3aea203b9c
2 changed files with 13 additions and 2 deletions

View File

@ -134,8 +134,8 @@ class ClassMetadata extends ClassMetadataInfo
{ {
$mapping = parent::_validateAndCompleteAssociationMapping($mapping); $mapping = parent::_validateAndCompleteAssociationMapping($mapping);
if ( ! class_exists($mapping['targetEntity']) ) { if ( ! \Doctrine\Common\ClassLoader::classExists($mapping['targetEntity']) ) {
#throw MappingException::invalidTargetEntityClass($mapping['targetEntity'], $this->name, $mapping['fieldName']); throw MappingException::invalidTargetEntityClass($mapping['targetEntity'], $this->name, $mapping['fieldName']);
} }
return $mapping; return $mapping;

View File

@ -482,4 +482,15 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
$this->setExpectedException("Doctrine\ORM\Mapping\MappingException", "Entity 'Doctrine\Tests\Models\CMS\CmsUser' has no method 'notfound' to be registered as lifecycle callback."); $this->setExpectedException("Doctrine\ORM\Mapping\MappingException", "Entity 'Doctrine\Tests\Models\CMS\CmsUser' has no method 'notfound' to be registered as lifecycle callback.");
$cm->addLifecycleCallback('notfound', 'postLoad'); $cm->addLifecycleCallback('notfound', 'postLoad');
} }
/**
* @group ImproveErrorMessages
*/
public function testTargetEntityNotFound()
{
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$this->setExpectedException("Doctrine\ORM\Mapping\MappingException", "The target-entity Doctrine\Tests\Models\CMS\UnknownClass cannot be found in 'Doctrine\Tests\Models\CMS\CmsUser#address'.");
$cm->mapManyToOne(array('fieldName' => 'address', 'targetEntity' => 'UnknownClass'));
}
} }