mention parent classes when not is a entity or mapped super class.
This commit is contained in:
parent
8a52e3033b
commit
f591e428c3
@ -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)
|
||||
|
46
tests/Doctrine/Tests/Models/DDC889/DDC889Class.php
Normal file
46
tests/Doctrine/Tests/Models/DDC889/DDC889Class.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
41
tests/Doctrine/Tests/Models/DDC889/DDC889SuperClass.php
Normal file
41
tests/Doctrine/Tests/Models/DDC889/DDC889SuperClass.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
@ -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');
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
||||
|
||||
$metadata->mapField(array(
|
||||
'id' => true,
|
||||
'fieldName' => 'id',
|
||||
'type' => 'integer',
|
||||
'columnName' => 'id',
|
||||
));
|
||||
|
||||
//$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
||||
|
||||
$metadata->mapField(array(
|
||||
'fieldName' => 'name',
|
||||
'type' => 'string',
|
||||
));
|
||||
$metadata->isMappedSuperclass = true;
|
||||
$metadata->setCustomRepositoryClass("Doctrine\Tests\Models\DDC889\DDC889SuperClass");
|
||||
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
|
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||
|
||||
<class name="Doctrine\Tests\Models\DDC889\DDC889Class">
|
||||
<id name="id" type="integer" column="id">
|
||||
<generator strategy="AUTO"/>
|
||||
</id>
|
||||
</class>
|
||||
|
||||
</doctrine-mapping>
|
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||
|
||||
<mapped-superclass name="Doctrine\Tests\Models\DDC889\DDC889SuperClass">
|
||||
<field name="name" column="name" type="string"/>
|
||||
</mapped-superclass>
|
||||
|
||||
</doctrine-mapping>
|
@ -0,0 +1,8 @@
|
||||
Doctrine\Tests\Models\DDC889\DDC889Class:
|
||||
type: class
|
||||
id:
|
||||
id:
|
||||
type: integer
|
||||
unsigned: true
|
||||
generator:
|
||||
strategy: AUTO
|
@ -0,0 +1,5 @@
|
||||
Doctrine\Tests\Models\DDC889\DDC889SuperClass:
|
||||
type: mappedSuperclass
|
||||
fields:
|
||||
name:
|
||||
type: string
|
Loading…
Reference in New Issue
Block a user