From 17ec1aab77586ce801ee009a9465e8bd467d7919 Mon Sep 17 00:00:00 2001 From: Dustin Thomson Date: Wed, 26 Nov 2014 21:51:17 -0700 Subject: [PATCH 1/8] Modified class metadata factory to have entity tables inherit indexes from mapped superclasses --- .../ORM/Mapping/ClassMetadataFactory.php | 18 +++++++ .../Mapping/BasicInheritanceMappingTest.php | 47 +++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 876f1ce57..71c57a78e 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -175,6 +175,24 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory $class->setPrimaryTable($parent->table); } + if ($parent && $parent->isMappedSuperclass) { + //Copy the table indices from the parent + + $indexTypes = array ('uniqueConstraints', 'indexes'); + + foreach ($indexTypes as $indexType) { + if (isset($parent->table[$indexType])) { + foreach ($parent->table[$indexType] as $indexName => $index) { + if (isset($class->table[$indexType][$indexName])) { + continue; // Let the inheriting table override indices + } + + $class->table[$indexType][$indexName] = $index; + } + } + } + } + if ($parent && $parent->cache) { $class->cache = $parent->cache; } diff --git a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php index 2eee28b85..790562194 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ORM\Mapping; use Doctrine\ORM\Mapping\ClassMetadataFactory; +use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\Tools\SchemaTool; class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase @@ -167,6 +168,22 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase $this->assertInstanceOf('Doctrine\ORM\Id\SequenceGenerator', $class->idGenerator); $this->assertEquals(array('allocationSize' => 1, 'initialValue' => 10, 'sequenceName' => 'foo'), $class->sequenceGeneratorDefinition); } + + /** + * Ensure indexes are inherited from the mapped superclass. + * + * @group DDC-3418 + */ + public function testMappedSuperclassIndex() + { + $class = $this->_factory->getMetadataFor(__NAMESPACE__ . '\\EntityIndexSubClass'); + /* @var $class ClassMetadataInfo */ + + $this->assertTrue(isset($class->fieldMappings['mapped1'])); + $this->assertTrue(isset($class->table['uniqueConstraints']['IDX_NAME_INDEX'])); + $this->assertTrue(isset($class->table['uniqueConstraints']['IDX_MAPPED1_INDEX'])); + $this->assertTrue(isset($class->table['indexes']['IDX_MAPPED2_INDEX'])); + } } class TransientBaseClass { @@ -206,6 +223,36 @@ class EntitySubClass2 extends MappedSuperclassBase { private $name; } +/** + * @MappedSuperclass + * + * @Table( + * uniqueConstraints={@UniqueConstraint(name="IDX_MAPPED1_INDEX",columns={"mapped1"})}, + * indexes={@Index(name="IDX_MAPPED2_INDEX", columns={"mapped2"})} + * ) + */ +class MappedSuperclassBaseIndex { + /** @Column(type="string") */ + private $mapped1; + /** @Column(type="string") */ + private $mapped2; +} + +/** + * @Entity + * + * @Table( + * uniqueConstraints={@UniqueConstraint(name="IDX_NAME_INDEX",columns={"name"})} + * ) + * */ +class EntityIndexSubClass extends MappedSuperclassBaseIndex +{ + /** @Id @Column(type="integer") */ + private $id; + /** @Column(type="string") */ + private $name; +} + /** * @Entity * @InheritanceType("SINGLE_TABLE") From 7648a3c590be92096eb32dc3b443dd70f603f613 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 27 Nov 2014 18:52:03 +0100 Subject: [PATCH 2/8] #1196 DDC-3418 DDC-3419 - refactoring inherited indexes copying logic into separate private method --- .../ORM/Mapping/ClassMetadataFactory.php | 45 ++++++++++++------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 71c57a78e..7414399aa 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -175,22 +175,8 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory $class->setPrimaryTable($parent->table); } - if ($parent && $parent->isMappedSuperclass) { - //Copy the table indices from the parent - - $indexTypes = array ('uniqueConstraints', 'indexes'); - - foreach ($indexTypes as $indexType) { - if (isset($parent->table[$indexType])) { - foreach ($parent->table[$indexType] as $indexName => $index) { - if (isset($class->table[$indexType][$indexName])) { - continue; // Let the inheriting table override indices - } - - $class->table[$indexType][$indexName] = $index; - } - } - } + if ($parent) { + $this->addInheritedIndexes($class, $parent); } if ($parent && $parent->cache) { @@ -433,6 +419,33 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory } } + /** + * Copy the table indices from the parent class superclass to the child class + * + * @param ClassMetadata $subClass + * @param ClassMetadata $parentClass + * + * @return void + */ + private function addInheritedIndexes(ClassMetadata $subClass, ClassMetadata $parentClass) + { + if (! $parentClass->isMappedSuperclass) { + return; + } + + foreach (array('uniqueConstraints', 'indexes') as $indexType) { + if (isset($parentClass->table[$indexType])) { + foreach ($parentClass->table[$indexType] as $indexName => $index) { + if (isset($subClass->table[$indexType][$indexName])) { + continue; // Let the inheriting table override indices + } + + $subClass->table[$indexType][$indexName] = $index; + } + } + } + } + /** * Adds inherited named queries to the subclass mapping. * From b761d84d4f181e3cbe7713ab1f0ded5d5b28f392 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 27 Nov 2014 18:54:10 +0100 Subject: [PATCH 3/8] #1196 DDC-3418 DDC-3419 - refactoring class metadata factory to avoid duplicate checks --- .../ORM/Mapping/ClassMetadataFactory.php | 50 ++++++++++--------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 7414399aa..efcf68bab 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -171,41 +171,43 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory } } - if ($parent && $parent->isInheritanceTypeSingleTable()) { - $class->setPrimaryTable($parent->table); - } - if ($parent) { - $this->addInheritedIndexes($class, $parent); - } + if ($parent->isInheritanceTypeSingleTable()) { + $class->setPrimaryTable($parent->table); + } - if ($parent && $parent->cache) { - $class->cache = $parent->cache; - } + if ($parent) { + $this->addInheritedIndexes($class, $parent); + } - if ($parent && $parent->containsForeignIdentifier) { - $class->containsForeignIdentifier = true; - } + if ($parent->cache) { + $class->cache = $parent->cache; + } - if ($parent && !empty($parent->namedQueries)) { - $this->addInheritedNamedQueries($class, $parent); - } + if ($parent->containsForeignIdentifier) { + $class->containsForeignIdentifier = true; + } - if ($parent && !empty($parent->namedNativeQueries)) { - $this->addInheritedNamedNativeQueries($class, $parent); - } + if ( ! empty($parent->namedQueries)) { + $this->addInheritedNamedQueries($class, $parent); + } - if ($parent && !empty($parent->sqlResultSetMappings)) { - $this->addInheritedSqlResultSetMappings($class, $parent); - } + if ( ! empty($parent->namedNativeQueries)) { + $this->addInheritedNamedNativeQueries($class, $parent); + } - if ($parent && !empty($parent->entityListeners) && empty($class->entityListeners)) { - $class->entityListeners = $parent->entityListeners; + if ( ! empty($parent->sqlResultSetMappings)) { + $this->addInheritedSqlResultSetMappings($class, $parent); + } + + if ( ! empty($parent->entityListeners) && empty($class->entityListeners)) { + $class->entityListeners = $parent->entityListeners; + } } $class->setParentClasses($nonSuperclassParents); - if ( $class->isRootEntity() && ! $class->isInheritanceTypeNone() && ! $class->discriminatorMap) { + if ($class->isRootEntity() && ! $class->isInheritanceTypeNone() && ! $class->discriminatorMap) { $this->addDefaultDiscriminatorMap($class); } From 084ce7ecc0106541b7cf85924853309099aa70ea Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 27 Nov 2014 18:57:49 +0100 Subject: [PATCH 4/8] #1196 DDC-3418 DDC-3419 - reducing test assets annotations spacing for readability --- .../Mapping/BasicInheritanceMappingTest.php | 54 ++++--------------- 1 file changed, 11 insertions(+), 43 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php index 790562194..dba07da08 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php @@ -225,7 +225,6 @@ class EntitySubClass2 extends MappedSuperclassBase { /** * @MappedSuperclass - * * @Table( * uniqueConstraints={@UniqueConstraint(name="IDX_MAPPED1_INDEX",columns={"mapped1"})}, * indexes={@Index(name="IDX_MAPPED2_INDEX", columns={"mapped2"})} @@ -238,13 +237,7 @@ class MappedSuperclassBaseIndex { private $mapped2; } -/** - * @Entity - * - * @Table( - * uniqueConstraints={@UniqueConstraint(name="IDX_NAME_INDEX",columns={"name"})} - * ) - * */ +/** @Entity @Table(uniqueConstraints={@UniqueConstraint(name="IDX_NAME_INDEX",columns={"name"})}) */ class EntityIndexSubClass extends MappedSuperclassBaseIndex { /** @Id @Column(type="integer") */ @@ -273,92 +266,67 @@ abstract class HierarchyBase public $id; } -/** - * @MappedSuperclass - */ +/** @MappedSuperclass */ abstract class HierarchyASuperclass extends HierarchyBase { /** @Column(type="string") */ public $a; } -/** - * @Entity - */ +/** @Entity */ class HierarchyBEntity extends HierarchyBase { /** @Column(type="string") */ public $b; } -/** - * @Entity - */ +/** @Entity */ class HierarchyC extends HierarchyBase { /** @Column(type="string") */ public $c; } -/** - * @Entity - */ +/** @Entity */ class HierarchyD extends HierarchyASuperclass { /** @Column(type="string") */ public $d; } -/** - * @Entity - */ +/** @Entity */ class HierarchyE extends HierarchyBEntity { /** @Column(type="string") */ public $e; } -/** - * @Entity - */ +/** @Entity */ class SuperclassEntity extends SuperclassBase { - } -/** - * @MappedSuperclass - */ +/** @MappedSuperclass */ abstract class SuperclassBase { /** * @Column(type="integer") @Id @GeneratedValue(strategy="SEQUENCE") * @SequenceGenerator(sequenceName="foo", initialValue=10) - * @var int */ public $id; } -/** - * @MappedSuperclass - */ +/** @MappedSuperclass */ abstract class MediumSuperclassBase extends SuperclassBase { - } -/** - * @Entity - */ +/** @Entity */ class MediumSuperclassEntity extends MediumSuperclassBase { - } -/** - * @Entity(repositoryClass = "Doctrine\ORM\EntityRepository") - */ +/** @Entity(repositoryClass = "Doctrine\ORM\EntityRepository") */ class SubclassWithRepository extends \Doctrine\Tests\Models\DDC869\DDC869Payment { - } From 34d2af8a774d7a8e223a19235b948786a96a6e5b Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 27 Nov 2014 19:06:42 +0100 Subject: [PATCH 5/8] #1196 DDC-3418 DDC-3419 - `assertArrayHasKey()` instead of `assertTrue(isset(...))` --- .../Mapping/BasicInheritanceMappingTest.php | 70 +++++++++---------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php index dba07da08..23d90207e 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php @@ -27,29 +27,29 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase { $class = $this->_factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\EntitySubClass'); - $this->assertTrue(empty($class->subClasses)); - $this->assertTrue(empty($class->parentClasses)); - $this->assertTrue(isset($class->fieldMappings['id'])); - $this->assertTrue(isset($class->fieldMappings['name'])); + $this->assertEmpty($class->subClasses); + $this->assertEmpty($class->parentClasses); + $this->assertArrayHasKey('id', $class->fieldMappings); + $this->assertArrayHasKey('name', $class->fieldMappings); } public function testGetMetadataForSubclassWithMappedSuperclass() { $class = $this->_factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\EntitySubClass2'); - $this->assertTrue(empty($class->subClasses)); - $this->assertTrue(empty($class->parentClasses)); + $this->assertEmpty($class->subClasses); + $this->assertEmpty($class->parentClasses); - $this->assertTrue(isset($class->fieldMappings['mapped1'])); - $this->assertTrue(isset($class->fieldMappings['mapped2'])); - $this->assertTrue(isset($class->fieldMappings['id'])); - $this->assertTrue(isset($class->fieldMappings['name'])); + $this->assertArrayHasKey('mapped1', $class->fieldMappings); + $this->assertArrayHasKey('mapped2', $class->fieldMappings); + $this->assertArrayHasKey('id', $class->fieldMappings); + $this->assertArrayHasKey('name', $class->fieldMappings); - $this->assertFalse(isset($class->fieldMappings['mapped1']['inherited'])); - $this->assertFalse(isset($class->fieldMappings['mapped2']['inherited'])); - $this->assertFalse(isset($class->fieldMappings['transient'])); + $this->assertArrayNotHasKey('inherited', $class->fieldMappings['mapped1']); + $this->assertArrayNotHasKey('inherited', $class->fieldMappings['mapped2']); + $this->assertArrayNotHasKey('transient', $class->fieldMappings); - $this->assertTrue(isset($class->associationMappings['mappedRelated1'])); + $this->assertArrayHasKey('mappedRelated1', $class->associationMappings); } /** @@ -59,25 +59,25 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase { $class = $this->_factory->getMetadataFor('Doctrine\Tests\Models\DDC869\DDC869CreditCardPayment'); - $this->assertTrue(isset($class->fieldMappings['id'])); - $this->assertTrue(isset($class->fieldMappings['value'])); - $this->assertTrue(isset($class->fieldMappings['creditCardNumber'])); - $this->assertEquals($class->customRepositoryClassName, "Doctrine\Tests\Models\DDC869\DDC869PaymentRepository"); + $this->assertArrayHasKey('id', $class->fieldMappings); + $this->assertArrayHasKey('value', $class->fieldMappings); + $this->assertArrayHasKey('creditCardNumber', $class->fieldMappings); + $this->assertEquals($class->customRepositoryClassName, 'Doctrine\Tests\Models\DDC869\DDC869PaymentRepository'); $class = $this->_factory->getMetadataFor('Doctrine\Tests\Models\DDC869\DDC869ChequePayment'); - $this->assertTrue(isset($class->fieldMappings['id'])); - $this->assertTrue(isset($class->fieldMappings['value'])); - $this->assertTrue(isset($class->fieldMappings['serialNumber'])); + $this->assertArrayHasKey('id', $class->fieldMappings); + $this->assertArrayHasKey('value', $class->fieldMappings); + $this->assertArrayHasKey('serialNumber', $class->fieldMappings); $this->assertEquals($class->customRepositoryClassName, "Doctrine\Tests\Models\DDC869\DDC869PaymentRepository"); // override repositoryClass $class = $this->_factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\SubclassWithRepository'); - $this->assertTrue(isset($class->fieldMappings['id'])); - $this->assertTrue(isset($class->fieldMappings['value'])); + $this->assertArrayHasKey('id', $class->fieldMappings); + $this->assertArrayHasKey('value', $class->fieldMappings); $this->assertEquals($class->customRepositoryClassName, "Doctrine\ORM\EntityRepository"); } @@ -92,9 +92,9 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase $class2 = unserialize(serialize($class)); $class2->wakeupReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); - $this->assertTrue(isset($class2->reflFields['mapped1'])); - $this->assertTrue(isset($class2->reflFields['mapped2'])); - $this->assertTrue(isset($class2->reflFields['mappedRelated1'])); + $this->assertArrayHasKey('mapped1', $class2->reflFields); + $this->assertArrayHasKey('mapped2', $class2->reflFields); + $this->assertArrayHasKey('mappedRelated1', $class2->reflFields); } /** @@ -104,9 +104,9 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase { $class = $this->_factory->getMetadataFor(__NAMESPACE__ . '\\HierarchyD'); - $this->assertTrue(isset($class->fieldMappings['id'])); - $this->assertTrue(isset($class->fieldMappings['a'])); - $this->assertTrue(isset($class->fieldMappings['d'])); + $this->assertArrayHasKey('id', $class->fieldMappings); + $this->assertArrayHasKey('a', $class->fieldMappings); + $this->assertArrayHasKey('d', $class->fieldMappings); } /** @@ -116,7 +116,7 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase { $this->setExpectedException('Doctrine\ORM\Mapping\MappingException', "Entity 'Doctrine\Tests\ORM\Mapping\HierarchyBEntity' has to be part of the discriminator map of 'Doctrine\Tests\ORM\Mapping\HierarchyBase' to be properly mapped in the inheritance hierarchy. Alternatively you can make 'Doctrine\Tests\ORM\Mapping\HierarchyBEntity' an abstract class to avoid this exception from occurring."); - $class = $this->_factory->getMetadataFor(__NAMESPACE__ . '\\HierarchyE'); + $this->_factory->getMetadataFor(__NAMESPACE__ . '\\HierarchyE'); } /** @@ -127,7 +127,7 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase { $class = $this->_factory->getMetadataFor(__NAMESPACE__ . '\\SuperclassEntity'); - $this->assertTrue(isset($class->fieldMappings['id'])); + $this->assertArrayHasKey('id', $class->fieldMappings); } /** @@ -179,10 +179,10 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase $class = $this->_factory->getMetadataFor(__NAMESPACE__ . '\\EntityIndexSubClass'); /* @var $class ClassMetadataInfo */ - $this->assertTrue(isset($class->fieldMappings['mapped1'])); - $this->assertTrue(isset($class->table['uniqueConstraints']['IDX_NAME_INDEX'])); - $this->assertTrue(isset($class->table['uniqueConstraints']['IDX_MAPPED1_INDEX'])); - $this->assertTrue(isset($class->table['indexes']['IDX_MAPPED2_INDEX'])); + $this->assertArrayHasKey('mapped1', $class->fieldMappings); + $this->assertArrayHasKey('IDX_NAME_INDEX', $class->table['uniqueConstraints']); + $this->assertArrayHasKey('IDX_MAPPED1_INDEX', $class->table['uniqueConstraints']); + $this->assertArrayHasKey('IDX_MAPPED2_INDEX', $class->table['indexes']); } } From 291b68634e59b255339269ae922e2f6a3cb83f9c Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 27 Nov 2014 19:07:16 +0100 Subject: [PATCH 6/8] #1196 DDC-3418 DDC-3419 - Adding missing docblock for test private property --- .../Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php index 23d90207e..929d5a916 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php @@ -8,6 +8,9 @@ use Doctrine\ORM\Tools\SchemaTool; class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase { + /** + * @var ClassMetadataFactory + */ private $_factory; protected function setUp() { From 71135972c612c8b9bb5e65b7cd5544f85b766518 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 27 Nov 2014 19:08:10 +0100 Subject: [PATCH 7/8] #1196 DDC-3418 DDC-3419 - Renamed `_factory` to `cmf` --- .../Mapping/BasicInheritanceMappingTest.php | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php index 929d5a916..2ae707620 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php @@ -11,11 +11,15 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase /** * @var ClassMetadataFactory */ - private $_factory; + private $cmf; + /** + * {@inheritDoc} + */ protected function setUp() { - $this->_factory = new ClassMetadataFactory(); - $this->_factory->setEntityManager($this->_getTestEntityManager()); + $this->cmf = new ClassMetadataFactory(); + + $this->cmf->setEntityManager($this->_getTestEntityManager()); } /** @@ -23,12 +27,12 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase */ public function testGetMetadataForTransientClassThrowsException() { - $this->_factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\TransientBaseClass'); + $this->cmf->getMetadataFor('Doctrine\Tests\ORM\Mapping\TransientBaseClass'); } public function testGetMetadataForSubclassWithTransientBaseClass() { - $class = $this->_factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\EntitySubClass'); + $class = $this->cmf->getMetadataFor('Doctrine\Tests\ORM\Mapping\EntitySubClass'); $this->assertEmpty($class->subClasses); $this->assertEmpty($class->parentClasses); @@ -38,7 +42,7 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase public function testGetMetadataForSubclassWithMappedSuperclass() { - $class = $this->_factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\EntitySubClass2'); + $class = $this->cmf->getMetadataFor('Doctrine\Tests\ORM\Mapping\EntitySubClass2'); $this->assertEmpty($class->subClasses); $this->assertEmpty($class->parentClasses); @@ -60,7 +64,7 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase */ public function testGetMetadataForSubclassWithMappedSuperclassWithRepository() { - $class = $this->_factory->getMetadataFor('Doctrine\Tests\Models\DDC869\DDC869CreditCardPayment'); + $class = $this->cmf->getMetadataFor('Doctrine\Tests\Models\DDC869\DDC869CreditCardPayment'); $this->assertArrayHasKey('id', $class->fieldMappings); $this->assertArrayHasKey('value', $class->fieldMappings); @@ -68,7 +72,7 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals($class->customRepositoryClassName, 'Doctrine\Tests\Models\DDC869\DDC869PaymentRepository'); - $class = $this->_factory->getMetadataFor('Doctrine\Tests\Models\DDC869\DDC869ChequePayment'); + $class = $this->cmf->getMetadataFor('Doctrine\Tests\Models\DDC869\DDC869ChequePayment'); $this->assertArrayHasKey('id', $class->fieldMappings); $this->assertArrayHasKey('value', $class->fieldMappings); @@ -77,7 +81,7 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase // override repositoryClass - $class = $this->_factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\SubclassWithRepository'); + $class = $this->cmf->getMetadataFor('Doctrine\Tests\ORM\Mapping\SubclassWithRepository'); $this->assertArrayHasKey('id', $class->fieldMappings); $this->assertArrayHasKey('value', $class->fieldMappings); @@ -90,7 +94,7 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase public function testSerializationWithPrivateFieldsFromMappedSuperclass() { - $class = $this->_factory->getMetadataFor(__NAMESPACE__ . '\\EntitySubClass2'); + $class = $this->cmf->getMetadataFor(__NAMESPACE__ . '\\EntitySubClass2'); $class2 = unserialize(serialize($class)); $class2->wakeupReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); @@ -105,7 +109,7 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase */ public function testUnmappedSuperclassInHierarchy() { - $class = $this->_factory->getMetadataFor(__NAMESPACE__ . '\\HierarchyD'); + $class = $this->cmf->getMetadataFor(__NAMESPACE__ . '\\HierarchyD'); $this->assertArrayHasKey('id', $class->fieldMappings); $this->assertArrayHasKey('a', $class->fieldMappings); @@ -119,7 +123,7 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase { $this->setExpectedException('Doctrine\ORM\Mapping\MappingException', "Entity 'Doctrine\Tests\ORM\Mapping\HierarchyBEntity' has to be part of the discriminator map of 'Doctrine\Tests\ORM\Mapping\HierarchyBase' to be properly mapped in the inheritance hierarchy. Alternatively you can make 'Doctrine\Tests\ORM\Mapping\HierarchyBEntity' an abstract class to avoid this exception from occurring."); - $this->_factory->getMetadataFor(__NAMESPACE__ . '\\HierarchyE'); + $this->cmf->getMetadataFor(__NAMESPACE__ . '\\HierarchyE'); } /** @@ -128,7 +132,7 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase */ public function testMappedSuperclassWithId() { - $class = $this->_factory->getMetadataFor(__NAMESPACE__ . '\\SuperclassEntity'); + $class = $this->cmf->getMetadataFor(__NAMESPACE__ . '\\SuperclassEntity'); $this->assertArrayHasKey('id', $class->fieldMappings); } @@ -139,7 +143,7 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase */ public function testGeneratedValueFromMappedSuperclass() { - $class = $this->_factory->getMetadataFor(__NAMESPACE__ . '\\SuperclassEntity'); + $class = $this->cmf->getMetadataFor(__NAMESPACE__ . '\\SuperclassEntity'); /* @var $class ClassMetadataInfo */ $this->assertInstanceOf('Doctrine\ORM\Id\SequenceGenerator', $class->idGenerator); @@ -152,7 +156,7 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase */ public function testSequenceDefinitionInHierarchyWithSandwichMappedSuperclass() { - $class = $this->_factory->getMetadataFor(__NAMESPACE__ . '\\HierarchyD'); + $class = $this->cmf->getMetadataFor(__NAMESPACE__ . '\\HierarchyD'); /* @var $class ClassMetadataInfo */ $this->assertInstanceOf('Doctrine\ORM\Id\SequenceGenerator', $class->idGenerator); @@ -165,7 +169,7 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase */ public function testMultipleMappedSuperclasses() { - $class = $this->_factory->getMetadataFor(__NAMESPACE__ . '\\MediumSuperclassEntity'); + $class = $this->cmf->getMetadataFor(__NAMESPACE__ . '\\MediumSuperclassEntity'); /* @var $class ClassMetadataInfo */ $this->assertInstanceOf('Doctrine\ORM\Id\SequenceGenerator', $class->idGenerator); @@ -179,7 +183,7 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase */ public function testMappedSuperclassIndex() { - $class = $this->_factory->getMetadataFor(__NAMESPACE__ . '\\EntityIndexSubClass'); + $class = $this->cmf->getMetadataFor(__NAMESPACE__ . '\\EntityIndexSubClass'); /* @var $class ClassMetadataInfo */ $this->assertArrayHasKey('mapped1', $class->fieldMappings); From b3fe0904ebbbb6bf7ca0ac6e90ee6114cf4e3774 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 27 Nov 2014 19:10:45 +0100 Subject: [PATCH 8/8] #1196 DDC-3418 DDC-3419 - Minor CS fixes, explicit `setExpectedException` calls --- .../Mapping/BasicInheritanceMappingTest.php | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php index 2ae707620..5a5f64277 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php @@ -2,9 +2,10 @@ namespace Doctrine\Tests\ORM\Mapping; +use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Mapping\ClassMetadataInfo; -use Doctrine\ORM\Tools\SchemaTool; +use Doctrine\Tests\Models\DDC869\DDC869Payment; class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase { @@ -22,11 +23,10 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase $this->cmf->setEntityManager($this->_getTestEntityManager()); } - /** - * @expectedException Doctrine\ORM\Mapping\MappingException - */ public function testGetMetadataForTransientClassThrowsException() { + $this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); + $this->cmf->getMetadataFor('Doctrine\Tests\ORM\Mapping\TransientBaseClass'); } @@ -77,7 +77,7 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase $this->assertArrayHasKey('id', $class->fieldMappings); $this->assertArrayHasKey('value', $class->fieldMappings); $this->assertArrayHasKey('serialNumber', $class->fieldMappings); - $this->assertEquals($class->customRepositoryClassName, "Doctrine\Tests\Models\DDC869\DDC869PaymentRepository"); + $this->assertEquals($class->customRepositoryClassName, 'Doctrine\Tests\Models\DDC869\DDC869PaymentRepository'); // override repositoryClass @@ -85,7 +85,7 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase $this->assertArrayHasKey('id', $class->fieldMappings); $this->assertArrayHasKey('value', $class->fieldMappings); - $this->assertEquals($class->customRepositoryClassName, "Doctrine\ORM\EntityRepository"); + $this->assertEquals($class->customRepositoryClassName, 'Doctrine\ORM\EntityRepository'); } /** @@ -97,7 +97,7 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase $class = $this->cmf->getMetadataFor(__NAMESPACE__ . '\\EntitySubClass2'); $class2 = unserialize(serialize($class)); - $class2->wakeupReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); + $class2->wakeupReflection(new RuntimeReflectionService); $this->assertArrayHasKey('mapped1', $class2->reflFields); $this->assertArrayHasKey('mapped2', $class2->reflFields); @@ -121,7 +121,12 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase */ public function testUnmappedEntityInHierarchy() { - $this->setExpectedException('Doctrine\ORM\Mapping\MappingException', "Entity 'Doctrine\Tests\ORM\Mapping\HierarchyBEntity' has to be part of the discriminator map of 'Doctrine\Tests\ORM\Mapping\HierarchyBase' to be properly mapped in the inheritance hierarchy. Alternatively you can make 'Doctrine\Tests\ORM\Mapping\HierarchyBEntity' an abstract class to avoid this exception from occurring."); + $this->setExpectedException( + 'Doctrine\ORM\Mapping\MappingException', + 'Entity \'Doctrine\Tests\ORM\Mapping\HierarchyBEntity\' has to be part of the discriminator map' + . ' of \'Doctrine\Tests\ORM\Mapping\HierarchyBase\' to be properly mapped in the inheritance hierarchy.' + . ' Alternatively you can make \'Doctrine\Tests\ORM\Mapping\HierarchyBEntity\' an abstract class to' + . ' avoid this exception from occurring.'); $this->cmf->getMetadataFor(__NAMESPACE__ . '\\HierarchyE'); } @@ -147,7 +152,10 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase /* @var $class ClassMetadataInfo */ $this->assertInstanceOf('Doctrine\ORM\Id\SequenceGenerator', $class->idGenerator); - $this->assertEquals(array('allocationSize' => 1, 'initialValue' => 10, 'sequenceName' => 'foo'), $class->sequenceGeneratorDefinition); + $this->assertEquals( + array('allocationSize' => 1, 'initialValue' => 10, 'sequenceName' => 'foo'), + $class->sequenceGeneratorDefinition + ); } /** @@ -160,7 +168,10 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase /* @var $class ClassMetadataInfo */ $this->assertInstanceOf('Doctrine\ORM\Id\SequenceGenerator', $class->idGenerator); - $this->assertEquals(array('allocationSize' => 1, 'initialValue' => 10, 'sequenceName' => 'foo'), $class->sequenceGeneratorDefinition); + $this->assertEquals( + array('allocationSize' => 1, 'initialValue' => 10, 'sequenceName' => 'foo'), + $class->sequenceGeneratorDefinition + ); } /** @@ -173,7 +184,10 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase /* @var $class ClassMetadataInfo */ $this->assertInstanceOf('Doctrine\ORM\Id\SequenceGenerator', $class->idGenerator); - $this->assertEquals(array('allocationSize' => 1, 'initialValue' => 10, 'sequenceName' => 'foo'), $class->sequenceGeneratorDefinition); + $this->assertEquals( + array('allocationSize' => 1, 'initialValue' => 10, 'sequenceName' => 'foo'), + $class->sequenceGeneratorDefinition + ); } /** @@ -334,6 +348,6 @@ class MediumSuperclassEntity extends MediumSuperclassBase } /** @Entity(repositoryClass = "Doctrine\ORM\EntityRepository") */ -class SubclassWithRepository extends \Doctrine\Tests\Models\DDC869\DDC869Payment +class SubclassWithRepository extends DDC869Payment { }