[2.0] DDC-268 - Exchanged DoctrineException for MappingException and added missing exception method (thanks to Christian Heinrich for the patch)
This commit is contained in:
parent
ee9aa005b2
commit
703ba989be
@ -21,8 +21,6 @@
|
|||||||
|
|
||||||
namespace Doctrine\ORM\Mapping;
|
namespace Doctrine\ORM\Mapping;
|
||||||
|
|
||||||
use Doctrine\Common\DoctrineException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A <tt>ClassMetadata</tt> instance holds all the object-relational mapping metadata
|
* A <tt>ClassMetadata</tt> instance holds all the object-relational mapping metadata
|
||||||
* of an entity and it's associations.
|
* of an entity and it's associations.
|
||||||
|
@ -21,8 +21,6 @@
|
|||||||
|
|
||||||
namespace Doctrine\ORM\Mapping;
|
namespace Doctrine\ORM\Mapping;
|
||||||
|
|
||||||
use Doctrine\Common\DoctrineException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A <tt>ClassMetadata</tt> instance holds all the object-relational mapping metadata
|
* A <tt>ClassMetadata</tt> instance holds all the object-relational mapping metadata
|
||||||
* of an entity and it's associations.
|
* of an entity and it's associations.
|
||||||
@ -740,7 +738,7 @@ class ClassMetadataInfo
|
|||||||
public function getSingleIdentifierFieldName()
|
public function getSingleIdentifierFieldName()
|
||||||
{
|
{
|
||||||
if ($this->isIdentifierComposite) {
|
if ($this->isIdentifierComposite) {
|
||||||
throw DoctrineException::singleIdNotAllowedOnCompositePrimaryKey($this->name);
|
throw MappingException::singleIdNotAllowedOnCompositePrimaryKey($this->name);
|
||||||
}
|
}
|
||||||
return $this->identifier[0];
|
return $this->identifier[0];
|
||||||
}
|
}
|
||||||
@ -1623,7 +1621,7 @@ class ClassMetadataInfo
|
|||||||
} else if ($mapping['type'] == 'datetime') {
|
} else if ($mapping['type'] == 'datetime') {
|
||||||
$mapping['default'] = 'CURRENT_TIMESTAMP';
|
$mapping['default'] = 'CURRENT_TIMESTAMP';
|
||||||
} else {
|
} else {
|
||||||
throw DoctrineException::unsupportedOptimisticLockingType($this->name, $mapping['fieldName'], $mapping['type']);
|
throw MappingException::unsupportedOptimisticLockingType($this->name, $mapping['fieldName'], $mapping['type']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,7 @@
|
|||||||
|
|
||||||
namespace Doctrine\ORM\Mapping\Driver;
|
namespace Doctrine\ORM\Mapping\Driver;
|
||||||
|
|
||||||
use Doctrine\Common\DoctrineException,
|
use Doctrine\Common\Cache\ArrayCache,
|
||||||
Doctrine\Common\Cache\ArrayCache,
|
|
||||||
Doctrine\Common\Annotations\AnnotationReader,
|
Doctrine\Common\Annotations\AnnotationReader,
|
||||||
Doctrine\ORM\Mapping\ClassMetadataInfo,
|
Doctrine\ORM\Mapping\ClassMetadataInfo,
|
||||||
Doctrine\ORM\Mapping\MappingException;
|
Doctrine\ORM\Mapping\MappingException;
|
||||||
@ -137,7 +136,7 @@ class AnnotationDriver implements Driver
|
|||||||
} else if (isset($classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass'])) {
|
} else if (isset($classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass'])) {
|
||||||
$metadata->isMappedSuperclass = true;
|
$metadata->isMappedSuperclass = true;
|
||||||
} else {
|
} else {
|
||||||
throw DoctrineException::classIsNotAValidEntityOrMappedSuperClass($className);
|
throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Evaluate DoctrineTable annotation
|
// Evaluate DoctrineTable annotation
|
||||||
@ -239,7 +238,7 @@ class AnnotationDriver implements Driver
|
|||||||
// @Column, @OneToOne, @OneToMany, @ManyToOne, @ManyToMany
|
// @Column, @OneToOne, @OneToMany, @ManyToOne, @ManyToMany
|
||||||
if ($columnAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Column')) {
|
if ($columnAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Column')) {
|
||||||
if ($columnAnnot->type == null) {
|
if ($columnAnnot->type == null) {
|
||||||
throw DoctrineException::propertyTypeIsRequired($property->getName());
|
throw MappingException::propertyTypeIsRequired($className, $property->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
$mapping['type'] = $columnAnnot->type;
|
$mapping['type'] = $columnAnnot->type;
|
||||||
@ -282,7 +281,7 @@ class AnnotationDriver implements Driver
|
|||||||
'initialValue' => $seqGeneratorAnnot->initialValue
|
'initialValue' => $seqGeneratorAnnot->initialValue
|
||||||
));
|
));
|
||||||
} else if ($tblGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\TableGenerator')) {
|
} else if ($tblGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\TableGenerator')) {
|
||||||
throw DoctrineException::tableIdGeneratorNotImplemented();
|
throw MappingException::tableIdGeneratorNotImplemented($className);
|
||||||
}
|
}
|
||||||
} else if ($oneToOneAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OneToOne')) {
|
} else if ($oneToOneAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OneToOne')) {
|
||||||
$mapping['targetEntity'] = $oneToOneAnnot->targetEntity;
|
$mapping['targetEntity'] = $oneToOneAnnot->targetEntity;
|
||||||
|
@ -21,8 +21,7 @@
|
|||||||
|
|
||||||
namespace Doctrine\ORM\Mapping\Driver;
|
namespace Doctrine\ORM\Mapping\Driver;
|
||||||
|
|
||||||
use Doctrine\Common\DoctrineException,
|
use Doctrine\Common\Cache\ArrayCache,
|
||||||
Doctrine\Common\Cache\ArrayCache,
|
|
||||||
Doctrine\Common\Annotations\AnnotationReader,
|
Doctrine\Common\Annotations\AnnotationReader,
|
||||||
Doctrine\DBAL\Schema\AbstractSchemaManager,
|
Doctrine\DBAL\Schema\AbstractSchemaManager,
|
||||||
Doctrine\ORM\Mapping\ClassMetadataInfo,
|
Doctrine\ORM\Mapping\ClassMetadataInfo,
|
||||||
|
@ -21,8 +21,7 @@
|
|||||||
|
|
||||||
namespace Doctrine\ORM\Mapping\Driver;
|
namespace Doctrine\ORM\Mapping\Driver;
|
||||||
|
|
||||||
use Doctrine\Common\DoctrineException,
|
use Doctrine\Common\Cache\ArrayCache,
|
||||||
Doctrine\Common\Cache\ArrayCache,
|
|
||||||
Doctrine\Common\Annotations\AnnotationReader,
|
Doctrine\Common\Annotations\AnnotationReader,
|
||||||
Doctrine\DBAL\Schema\AbstractSchemaManager,
|
Doctrine\DBAL\Schema\AbstractSchemaManager,
|
||||||
Doctrine\ORM\Mapping\ClassMetadataInfo,
|
Doctrine\ORM\Mapping\ClassMetadataInfo,
|
||||||
|
@ -57,7 +57,7 @@ class XmlDriver extends AbstractFileDriver
|
|||||||
} else if ($xmlRoot->getName() == 'mapped-superclass') {
|
} else if ($xmlRoot->getName() == 'mapped-superclass') {
|
||||||
$metadata->isMappedSuperclass = true;
|
$metadata->isMappedSuperclass = true;
|
||||||
} else {
|
} else {
|
||||||
throw DoctrineException::classIsNotAValidEntityOrMapperSuperClass($className);
|
throw MappingException::classIsNotAValidEntityOrMapperSuperClass($className);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Evaluate <entity...> attributes
|
// Evaluate <entity...> attributes
|
||||||
@ -200,7 +200,7 @@ class XmlDriver extends AbstractFileDriver
|
|||||||
'initialValue' => $seqGeneratorAnnot->{'initial-value'}
|
'initialValue' => $seqGeneratorAnnot->{'initial-value'}
|
||||||
));
|
));
|
||||||
} else if (isset($idElement->{'table-generator'})) {
|
} else if (isset($idElement->{'table-generator'})) {
|
||||||
throw DoctrineException::tableIdGeneratorNotImplemented();
|
throw MappingException::tableIdGeneratorNotImplemented($className);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
namespace Doctrine\ORM\Mapping\Driver;
|
namespace Doctrine\ORM\Mapping\Driver;
|
||||||
|
|
||||||
use Doctrine\ORM\Mapping\ClassMetadataInfo,
|
use Doctrine\ORM\Mapping\ClassMetadataInfo,
|
||||||
Doctrine\Common\DoctrineException,
|
|
||||||
Doctrine\ORM\Mapping\MappingException;
|
Doctrine\ORM\Mapping\MappingException;
|
||||||
|
|
||||||
if ( ! class_exists('sfYaml', false)) {
|
if ( ! class_exists('sfYaml', false)) {
|
||||||
@ -65,7 +64,7 @@ class YamlDriver extends AbstractFileDriver
|
|||||||
} else if ($element['type'] == 'mappedSuperclass') {
|
} else if ($element['type'] == 'mappedSuperclass') {
|
||||||
$metadata->isMappedSuperclass = true;
|
$metadata->isMappedSuperclass = true;
|
||||||
} else {
|
} else {
|
||||||
throw DoctrineException::classIsNotAValidEntityOrMapperSuperClass($className);
|
throw MappingException::classIsNotAValidEntityOrMapperSuperClass($className);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Evaluate root level properties
|
// Evaluate root level properties
|
||||||
@ -165,6 +164,10 @@ class YamlDriver extends AbstractFileDriver
|
|||||||
// Evaluate fields
|
// Evaluate fields
|
||||||
if (isset($element['fields'])) {
|
if (isset($element['fields'])) {
|
||||||
foreach ($element['fields'] as $name => $fieldMapping) {
|
foreach ($element['fields'] as $name => $fieldMapping) {
|
||||||
|
if (!isset($fieldMapping['type'])) {
|
||||||
|
throw MappingException::propertyTypeIsRequired($className, $name);
|
||||||
|
}
|
||||||
|
|
||||||
$e = explode('(', $fieldMapping['type']);
|
$e = explode('(', $fieldMapping['type']);
|
||||||
$fieldMapping['type'] = $e[0];
|
$fieldMapping['type'] = $e[0];
|
||||||
if (isset($e[1])) {
|
if (isset($e[1])) {
|
||||||
@ -185,7 +188,7 @@ class YamlDriver extends AbstractFileDriver
|
|||||||
if (isset($fieldMapping['sequenceGenerator'])) {
|
if (isset($fieldMapping['sequenceGenerator'])) {
|
||||||
$metadata->setSequenceGeneratorDefinition($fieldMapping['sequenceGenerator']);
|
$metadata->setSequenceGeneratorDefinition($fieldMapping['sequenceGenerator']);
|
||||||
} else if (isset($fieldMapping['tableGenerator'])) {
|
} else if (isset($fieldMapping['tableGenerator'])) {
|
||||||
throw DoctrineException::tableIdGeneratorNotImplemented();
|
throw MappingException::tableIdGeneratorNotImplemented($className);
|
||||||
}
|
}
|
||||||
if (isset($fieldMapping['column'])) {
|
if (isset($fieldMapping['column'])) {
|
||||||
$mapping['columnName'] = $fieldMapping['column'];
|
$mapping['columnName'] = $fieldMapping['column'];
|
||||||
|
@ -127,10 +127,43 @@ class MappingException extends \Doctrine\ORM\ORMException
|
|||||||
return new self('The column ' . $joinColumn . ' must be mapped to a field in class '
|
return new self('The column ' . $joinColumn . ' must be mapped to a field in class '
|
||||||
. $className . ' since it is referenced by a join column of another class.');
|
. $className . ' since it is referenced by a join column of another class.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function classIsNotAValidEntityOrMappedSuperClass($className)
|
||||||
|
{
|
||||||
|
return new self('Class '.$className.' is not a valid entity or mapped super class.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function propertyTypeIsRequired($className, $propertyName)
|
||||||
|
{
|
||||||
|
return new self("The attribute 'type' is required for the column description of property ".$className."::\$".$propertyName.".");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function tableIdGeneratorNotImplemented($className)
|
||||||
|
{
|
||||||
|
return new self("TableIdGenerator is not yet implemented for use with class ".$className);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param string $entity The entity's name
|
||||||
|
* @param string $fieldName The name of the field that was already declared
|
||||||
|
*/
|
||||||
|
public static function duplicateFieldMapping($entity, $fieldName) {
|
||||||
|
return new self('Property "'.$fieldName.'" in "'.$entity.'" was already declared, but it must be declared only once');
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function singleIdNotAllowedOnCompositePrimaryKey($entity) {
|
||||||
|
return new self('Single id is not allowed on composite primary key in entity '.$entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function unsupportedOptimisticLockingType($entity, $fieldName, $unsupportedType) {
|
||||||
|
return new self('Locking type "'.$unsupportedType.'" (specified in "'.$entity.'", field "'.$fieldName.'") '
|
||||||
|
.'is not supported by Doctrine.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public static function annotationDriverRequiresConfiguredDirectoryPath()
|
public static function annotationDriverRequiresConfiguredDirectoryPath()
|
||||||
{
|
{
|
||||||
return new self('The annotation driver needs to have a directory path');
|
return new self('The annotation driver needs to have a directory path');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -22,6 +22,7 @@ class AllTests
|
|||||||
$suite->addTestSuite('Doctrine\Tests\ORM\Mapping\ClassMetadataTest');
|
$suite->addTestSuite('Doctrine\Tests\ORM\Mapping\ClassMetadataTest');
|
||||||
$suite->addTestSuite('Doctrine\Tests\ORM\Mapping\XmlMappingDriverTest');
|
$suite->addTestSuite('Doctrine\Tests\ORM\Mapping\XmlMappingDriverTest');
|
||||||
$suite->addTestSuite('Doctrine\Tests\ORM\Mapping\YamlMappingDriverTest');
|
$suite->addTestSuite('Doctrine\Tests\ORM\Mapping\YamlMappingDriverTest');
|
||||||
|
$suite->addTestSuite('Doctrine\Tests\ORM\Mapping\AnnotationDriverTest');
|
||||||
$suite->addTestSuite('Doctrine\Tests\ORM\Mapping\ClassMetadataFactoryTest');
|
$suite->addTestSuite('Doctrine\Tests\ORM\Mapping\ClassMetadataFactoryTest');
|
||||||
$suite->addTestSuite('Doctrine\Tests\ORM\Mapping\ClassMetadataLoadEventTest');
|
$suite->addTestSuite('Doctrine\Tests\ORM\Mapping\ClassMetadataLoadEventTest');
|
||||||
$suite->addTestSuite('Doctrine\Tests\ORM\Mapping\BasicInheritanceMappingTest');
|
$suite->addTestSuite('Doctrine\Tests\ORM\Mapping\BasicInheritanceMappingTest');
|
||||||
|
49
tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php
Normal file
49
tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Doctrine\Tests\ORM\Mapping;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||||
|
use Doctrine\ORM\Events;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../../TestInit.php';
|
||||||
|
|
||||||
|
class AnnotationDriverTest extends \Doctrine\Tests\OrmTestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @group DDC-268
|
||||||
|
*/
|
||||||
|
public function testLoadMetadataForNonEntityThrowsException()
|
||||||
|
{
|
||||||
|
$cm = new ClassMetadata('stdClass');
|
||||||
|
$reader = new \Doctrine\Common\Annotations\AnnotationReader(new \Doctrine\Common\Cache\ArrayCache());
|
||||||
|
$annotationDriver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader);
|
||||||
|
|
||||||
|
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException');
|
||||||
|
$annotationDriver->loadMetadataForClass('stdClass', $cm);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group DDC-268
|
||||||
|
*/
|
||||||
|
public function testColumnWithMissingTypeThrowsException()
|
||||||
|
{
|
||||||
|
$cm = new ClassMetadata('Doctrine\Tests\ORM\Mapping\InvalidColumn');
|
||||||
|
$reader = new \Doctrine\Common\Annotations\AnnotationReader(new \Doctrine\Common\Cache\ArrayCache());
|
||||||
|
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
|
||||||
|
$annotationDriver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader);
|
||||||
|
|
||||||
|
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException',
|
||||||
|
"The attribute 'type' is required for the column description of property Doctrine\\Tests\\ORM\\Mapping\\InvalidColumn::\$id");
|
||||||
|
$annotationDriver->loadMetadataForClass('Doctrine\Tests\ORM\Mapping\InvalidColumn', $cm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
*/
|
||||||
|
class InvalidColumn
|
||||||
|
{
|
||||||
|
/** @Id @Column */
|
||||||
|
public $id;
|
||||||
|
}
|
||||||
|
|
@ -15,7 +15,7 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException Doctrine\Common\DoctrineException
|
* @expectedException Doctrine\ORM\Mapping\MappingException
|
||||||
*/
|
*/
|
||||||
public function testGetMetadataForTransientClassThrowsException()
|
public function testGetMetadataForTransientClassThrowsException()
|
||||||
{
|
{
|
||||||
|
@ -113,4 +113,28 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
|
|
||||||
$this->assertEquals("DoctrineGlobal_Article", $cm->subClasses[0]);
|
$this->assertEquals("DoctrineGlobal_Article", $cm->subClasses[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group DDC-268
|
||||||
|
*/
|
||||||
|
public function testSetInvalidVersionMapping_ThrowsException()
|
||||||
|
{
|
||||||
|
$field = array();
|
||||||
|
$field['fieldName'] = 'foo';
|
||||||
|
$field['type'] = 'string';
|
||||||
|
|
||||||
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
|
||||||
|
|
||||||
|
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException');
|
||||||
|
$cm->setVersionMapping($field);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetSingleIdentifierFieldName_MultipleIdentifierEntity_ThrowsException()
|
||||||
|
{
|
||||||
|
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
|
||||||
|
$cm->isIdentifierComposite = true;
|
||||||
|
|
||||||
|
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException');
|
||||||
|
$cm->getSingleIdentifierFieldName();
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user