diff --git a/lib/Doctrine/ORM/Mapping/MappingException.php b/lib/Doctrine/ORM/Mapping/MappingException.php index 0eff17cd6..ad2ad9307 100644 --- a/lib/Doctrine/ORM/Mapping/MappingException.php +++ b/lib/Doctrine/ORM/Mapping/MappingException.php @@ -34,8 +34,18 @@ class MappingException extends \Doctrine\ORM\ORMException public static function identifierRequired($entityName) { - return new self("No identifier/primary key specified for Entity '$entityName'." - . " Every Entity must have an identifier/primary key."); + if (null != ($parent = get_parent_class($entityName))) { + return new self(sprintf( + 'No identifier/primary key specified for Entity "%s" sub classe of "%s". Every Entity must have an identifier/primary key.', + $className, $parent + )); + } + + return new self(sprintf( + 'No identifier/primary key specified for Entity "%s". Every Entity must have an identifier/primary key.', + $entityName + )); + } public static function invalidInheritanceType($entityName, $type) @@ -144,7 +154,17 @@ class MappingException extends \Doctrine\ORM\ORMException public static function classIsNotAValidEntityOrMappedSuperClass($className) { - return new self('Class '.$className.' is not a valid entity or mapped super class.'); + if (null != ($parent = get_parent_class($className))) { + return new self(sprintf( + 'Class "%s" sub classe of "%s" is not a valid entity or mapped super class.', + $className, $parent + )); + } + + return new self(sprintf( + 'Class "%s" is not a valid entity or mapped super class.', + $className + )); } public static function propertyTypeIsRequired($className, $propertyName) diff --git a/tests/Doctrine/Tests/Models/DDC889/DDC889Class.php b/tests/Doctrine/Tests/Models/DDC889/DDC889Class.php new file mode 100644 index 000000000..7520568b0 --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC889/DDC889Class.php @@ -0,0 +1,46 @@ +. + */ + +namespace Doctrine\Tests\Models\DDC889; + +class DDC889Class extends DDC889SuperClass +{ + + /** + * @Id + * @Column(type="integer") + * @GeneratedValue + */ + protected $id; + + + public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) + { + $metadata->mapField(array( + 'id' => true, + 'fieldName' => 'id', + 'type' => 'integer', + 'columnName' => 'id', + )); + + $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadataInfo::GENERATOR_TYPE_AUTO); + } + +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/Models/DDC889/DDC889SuperClass.php b/tests/Doctrine/Tests/Models/DDC889/DDC889SuperClass.php new file mode 100644 index 000000000..7cffe488b --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC889/DDC889SuperClass.php @@ -0,0 +1,41 @@ +. + */ + +namespace Doctrine\Tests\Models\DDC889; + +/** + * @MappedSuperclass + */ +class DDC889SuperClass +{ + + /** @Column() */ + protected $name; + + public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) + { + $metadata->mapField(array( + 'fieldName' => 'name', + )); + + $metadata->isMappedSuperclass = true; + $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadataInfo::GENERATOR_TYPE_NONE); + } +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index b15481bdb..185bbeda3 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -461,6 +461,22 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals("ENUM('ONE','TWO')", $class->discriminatorColumn['columnDefinition']); $this->assertEquals("dtype", $class->discriminatorColumn['name']); } + + /** + * @group DDC-889 + * @expectedException Doctrine\ORM\Mapping\MappingException + * @expectedExceptionMessage Class "Doctrine\Tests\Models\DDC889\DDC889Class" sub classe of "Doctrine\Tests\Models\DDC889\DDC889SuperClass" is not a valid entity or mapped super class. + */ + public function testinvalidEntityOrMappedSuperClassShouldMentionParentClasses() + { + $driver = $this->_loadDriver(); + $em = $this->_getTestEntityManager(); + $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory(); + $em->getConfiguration()->setMetadataDriverImpl($driver); + $factory->setEntityManager($em); + + $factory->getMetadataFor('Doctrine\Tests\Models\DDC889\DDC889Class'); + } } /** diff --git a/tests/Doctrine/Tests/ORM/Mapping/PHPMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/PHPMappingDriverTest.php index e14828e00..0aec237bc 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/PHPMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/PHPMappingDriverTest.php @@ -25,4 +25,14 @@ class PHPMappingDriverTest extends AbstractMappingDriverTest return new PHPDriver($path); } + + /** + * All class are entitier for php driver + * + * @group DDC-889 + */ + public function testinvalidEntityOrMappedSuperClassShouldMentionParentClasses() + { + $this->createClassMetadata('Doctrine\Tests\Models\DDC889\DDC889Class'); + } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/StaticPHPMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/StaticPHPMappingDriverTest.php index 1a5a2074e..ab84a48bd 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/StaticPHPMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/StaticPHPMappingDriverTest.php @@ -14,4 +14,15 @@ class StaticPHPMappingDriverTest extends AbstractMappingDriverTest { return new StaticPHPDriver(__DIR__ . DIRECTORY_SEPARATOR . 'php'); } + + + /** + * All class with static::loadMetadata are entities for php driver + * + * @group DDC-889 + */ + public function testinvalidEntityOrMappedSuperClassShouldMentionParentClasses() + { + $this->createClassMetadata('Doctrine\Tests\Models\DDC889\DDC889Class'); + } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php index 6a852bc69..3106bc1d3 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php @@ -84,6 +84,16 @@ class XmlMappingDriverTest extends AbstractMappingDriverTest array(__DIR__ . "/xml/CatNoId.dcm.xml"), ); } + + /** + * @group DDC-889 + * @expectedException Doctrine\ORM\Mapping\MappingException + * @expectedExceptionMessage Invalid mapping file 'Doctrine.Tests.Models.DDC889.DDC889Class.dcm.xml' for class 'Doctrine\Tests\Models\DDC889\DDC889Class'. + */ + public function testinvalidEntityOrMappedSuperClassShouldMentionParentClasses() + { + $this->createClassMetadata('Doctrine\Tests\Models\DDC889\DDC889Class'); + } } class CTI diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC889.DDC889Class.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC889.DDC889Class.php new file mode 100644 index 000000000..90cfdc10b --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC889.DDC889Class.php @@ -0,0 +1,12 @@ +mapField(array( + 'id' => true, + 'fieldName' => 'id', + 'type' => 'integer', + 'columnName' => 'id', +)); + +//$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC889.DDC889SuperClass.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC889.DDC889SuperClass.php new file mode 100644 index 000000000..e56cc9bfd --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC889.DDC889SuperClass.php @@ -0,0 +1,11 @@ +mapField(array( + 'fieldName' => 'name', + 'type' => 'string', + )); +$metadata->isMappedSuperclass = true; +$metadata->setCustomRepositoryClass("Doctrine\Tests\Models\DDC889\DDC889SuperClass"); +$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889Class.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889Class.dcm.xml new file mode 100644 index 000000000..4a8935c9a --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889Class.dcm.xml @@ -0,0 +1,13 @@ + + + + + + + + + + \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889SuperClass.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889SuperClass.dcm.xml new file mode 100644 index 000000000..48fa4fb83 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC889.DDC889SuperClass.dcm.xml @@ -0,0 +1,11 @@ + + + + + + + + \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC889.DDC889Class.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC889.DDC889Class.dcm.yml new file mode 100644 index 000000000..567e5d585 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC889.DDC889Class.dcm.yml @@ -0,0 +1,8 @@ +Doctrine\Tests\Models\DDC889\DDC889Class: + type: class + id: + id: + type: integer + unsigned: true + generator: + strategy: AUTO \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC889.DDC889SuperClass.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC889.DDC889SuperClass.dcm.yml new file mode 100644 index 000000000..7974d552d --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC889.DDC889SuperClass.dcm.yml @@ -0,0 +1,5 @@ +Doctrine\Tests\Models\DDC889\DDC889SuperClass: + type: mappedSuperclass + fields: + name: + type: string \ No newline at end of file