1
0
mirror of synced 2025-01-29 19:41:45 +03:00

Merge pull request #310 from FabioBatSilva/DDC-889

[DDC-889] Mention parent class for debugging purposes.
This commit is contained in:
Benjamin Eberlei 2012-03-30 12:55:49 -07:00
commit 04a4f2fc24
17 changed files with 290 additions and 17 deletions

View File

@ -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 class of "%s". Every Entity must have an identifier/primary key.',
$entityName, $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 class 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)

View 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);
}
}

View File

@ -0,0 +1,33 @@
<?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;
/**
* @Entity
*/
class DDC889Entity extends DDC889SuperClass
{
public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata)
{
}
}

View 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);
}
}

View File

@ -24,6 +24,21 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
return $class;
}
/**
* @param \Doctrine\ORM\EntityManager $entityClassName
* @return \Doctrine\ORM\Mapping\ClassMetadataFactory
*/
protected function createClassMetadataFactory(\Doctrine\ORM\EntityManager $em = null)
{
$driver = $this->_loadDriver();
$em = $em ?: $this->_getTestEntityManager();
$factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
$em->getConfiguration()->setMetadataDriverImpl($driver);
$factory->setEntityManager($em);
return $factory;
}
public function testLoadMapping()
{
$entityClassName = 'Doctrine\Tests\ORM\Mapping\User';
@ -329,12 +344,8 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
*/
public function testMappedSuperclassWithRepository()
{
$driver = $this->_loadDriver();
$em = $this->_getTestEntityManager();
$factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
$em->getConfiguration()->setMetadataDriverImpl($driver);
$factory->setEntityManager($em);
$factory = $this->createClassMetadataFactory($em);
$class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC869\DDC869CreditCardPayment');
@ -365,12 +376,8 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
*/
public function testDefaultFieldType()
{
$driver = $this->_loadDriver();
$em = $this->_getTestEntityManager();
$factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
$em->getConfiguration()->setMetadataDriverImpl($driver);
$factory->setEntityManager($em);
$factory = $this->createClassMetadataFactory($em);
$class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC1476\DDC1476EntityWithDefaultFieldType');
@ -429,11 +436,8 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
*/
public function testNamingStrategy()
{
$driver = $this->_loadDriver();
$em = $this->_getTestEntityManager();
$factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
$em->getConfiguration()->setMetadataDriverImpl($driver);
$factory->setEntityManager($em);
$factory = $this->createClassMetadataFactory($em);
$this->assertInstanceOf('Doctrine\ORM\Mapping\DefaultNamingStrategy', $em->getConfiguration()->getNamingStrategy());
@ -461,6 +465,29 @@ 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 class of "Doctrine\Tests\Models\DDC889\DDC889SuperClass" is not a valid entity or mapped super class.
*/
public function testInvalidEntityOrMappedSuperClassShouldMentionParentClasses()
{
$this->createClassMetadata('Doctrine\Tests\Models\DDC889\DDC889Class');
}
/**
* @group DDC-889
* @expectedException Doctrine\ORM\Mapping\MappingException
* @expectedExceptionMessage No identifier/primary key specified for Entity "Doctrine\Tests\Models\DDC889\DDC889Entity" sub class of "Doctrine\Tests\Models\DDC889\DDC889SuperClass". Every Entity must have an identifier/primary key.
*/
public function testIdentifierRequiredShouldMentionParentClasses()
{
$factory = $this->createClassMetadataFactory();
$factory->getMetadataFor('Doctrine\Tests\Models\DDC889\DDC889Entity');
}
}
/**

View File

@ -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');
}
}

View File

@ -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');
}
}

View File

@ -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

View File

@ -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);

View File

@ -0,0 +1,3 @@
<?php
use Doctrine\ORM\Mapping\ClassMetadataInfo;

View File

@ -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);

View File

@ -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>

View File

@ -0,0 +1,10 @@
<?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">
<entity name="Doctrine\Tests\Models\DDC889\DDC889Entity">
</entity>
</doctrine-mapping>

View File

@ -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>

View File

@ -0,0 +1,8 @@
Doctrine\Tests\Models\DDC889\DDC889Class:
type: class
id:
id:
type: integer
unsigned: true
generator:
strategy: AUTO

View File

@ -0,0 +1,2 @@
Doctrine\Tests\Models\DDC889\DDC889Entity:
type: entity

View File

@ -0,0 +1,5 @@
Doctrine\Tests\Models\DDC889\DDC889SuperClass:
type: mappedSuperclass
fields:
name:
type: string