1
0
mirror of synced 2024-12-14 07:06:04 +03:00

Merge branch 'DDC-996'

This commit is contained in:
Benjamin Eberlei 2011-01-23 14:21:23 +01:00
commit 482ff2d009
3 changed files with 17 additions and 6 deletions

View File

@ -658,8 +658,8 @@ class ClassMetadataInfo
protected function _validateAndCompleteFieldMapping(array &$mapping)
{
// Check mandatory fields
if ( ! isset($mapping['fieldName'])) {
throw MappingException::missingFieldName($this->name, $mapping);
if ( ! isset($mapping['fieldName']) || strlen($mapping['fieldName']) == 0) {
throw MappingException::missingFieldName($this->name);
}
if ( ! isset($mapping['type'])) {
// Default to string
@ -749,8 +749,8 @@ class ClassMetadataInfo
// Mandatory attributes for both sides
// Mandatory: fieldName, targetEntity
if ( ! isset($mapping['fieldName'])) {
throw MappingException::missingFieldName();
if ( ! isset($mapping['fieldName']) || strlen($mapping['fieldName']) == 0) {
throw MappingException::missingFieldName($this->name);
}
if ( ! isset($mapping['targetEntity'])) {
throw MappingException::missingTargetEntity($mapping['fieldName']);

View File

@ -48,9 +48,9 @@ class MappingException extends \Doctrine\ORM\ORMException
return new self("Id generators can't be used with a composite id.");
}
public static function missingFieldName()
public static function missingFieldName($entity)
{
return new self("The association mapping misses the 'fieldName' attribute.");
return new self("The field or association mapping misses the 'fieldName' attribute in entity '$entity'.");
}
public static function missingTargetEntity($fieldName)

View File

@ -379,4 +379,15 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
'joinColumns' => array(),
));
}
/**
* @group DDC-996
*/
public function testEmptyFieldNameThrowsException()
{
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException',
"The field or association mapping misses the 'fieldName' attribute in entity 'Doctrine\Tests\Models\CMS\CmsUser'.");
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->mapField(array('fieldName' => ''));
}
}