From 82f7d6cad20d563700a15139c2dca9a69d0661d2 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Wed, 7 Sep 2011 17:27:05 -0300 Subject: [PATCH 1/6] starts work with mapped superclass repository --- .../ORM/Mapping/ClassMetadataFactory.php | 1 + .../ORM/Mapping/Driver/AnnotationDriver.php | 6 ++- .../Mapping/Driver/DoctrineAnnotations.php | 4 +- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 9 ++-- .../ORM/Mapping/Driver/YamlDriver.php | 9 ++-- .../Mapping/BasicInheritanceMappingTest.php | 50 +++++++++++++++++++ 6 files changed, 71 insertions(+), 8 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 2044932d6..98ef3fd6e 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -274,6 +274,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface $class->setDiscriminatorMap($parent->discriminatorMap); $class->setLifecycleCallbacks($parent->lifecycleCallbacks); $class->setChangeTrackingPolicy($parent->changeTrackingPolicy); + $class->setCustomRepositoryClass($parent->customRepositoryClassName); } // Invoke driver diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index ee7db54ac..afb89f083 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -147,12 +147,16 @@ class AnnotationDriver implements Driver // Evaluate Entity annotation if (isset($classAnnotations['Doctrine\ORM\Mapping\Entity'])) { $entityAnnot = $classAnnotations['Doctrine\ORM\Mapping\Entity']; - $metadata->setCustomRepositoryClass($entityAnnot->repositoryClass); + if($entityAnnot->repositoryClass !== null) { + $metadata->setCustomRepositoryClass($entityAnnot->repositoryClass); + } if ($entityAnnot->readOnly) { $metadata->markReadOnly(); } } else if (isset($classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass'])) { + $mappedSuperclassAnnot = $classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass']; + $metadata->setCustomRepositoryClass($mappedSuperclassAnnot->repositoryClass); $metadata->isMappedSuperclass = true; } else { throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className); diff --git a/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php b/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php index e6a674b38..6e5b36a45 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php @@ -36,7 +36,9 @@ final class Entity extends Annotation { * @Annotation * @Target("CLASS") */ -final class MappedSuperclass extends Annotation {} +final class MappedSuperclass extends Annotation { + public $repositoryClass; +} /** * @Annotation diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 20631d63c..b676ca8da 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -52,13 +52,16 @@ class XmlDriver extends AbstractFileDriver $xmlRoot = $this->getElement($className); if ($xmlRoot->getName() == 'entity') { - $metadata->setCustomRepositoryClass( - isset($xmlRoot['repository-class']) ? (string)$xmlRoot['repository-class'] : null - ); + if (isset($xmlRoot['repository-class'])) { + $metadata->setCustomRepositoryClass((string)$xmlRoot['repository-class']); + } if (isset($xmlRoot['read-only']) && $xmlRoot['read-only'] == "true") { $metadata->markReadOnly(); } } else if ($xmlRoot->getName() == 'mapped-superclass') { + $metadata->setCustomRepositoryClass( + isset($xmlRoot['repository-class']) ? (string)$xmlRoot['repository-class'] : null + ); $metadata->isMappedSuperclass = true; } else { throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className); diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index a47d56fa1..a2c5402b6 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -46,13 +46,16 @@ class YamlDriver extends AbstractFileDriver $element = $this->getElement($className); if ($element['type'] == 'entity') { - $metadata->setCustomRepositoryClass( - isset($element['repositoryClass']) ? $element['repositoryClass'] : null - ); + if (isset($element['repositoryClass'])) { + $metadata->setCustomRepositoryClass($element['repositoryClass']); + } if (isset($element['readOnly']) && $element['readOnly'] == true) { $metadata->markReadOnly(); } } else if ($element['type'] == 'mappedSuperclass') { + $metadata->setCustomRepositoryClass( + isset($element['repositoryClass']) ? $element['repositoryClass'] : null + ); $metadata->isMappedSuperclass = true; } else { throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className); diff --git a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php index d5aac63f9..e5fa6d220 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php @@ -52,6 +52,30 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase $this->assertTrue(isset($class->associationMappings['mappedRelated1'])); } + + public function testGetMetadataForSubclassWithMappedSuperclassWhithRepository() + { + $class = $this->_factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\SubclassWithoutRepository'); + + $this->assertTrue(empty($class->subClasses)); + $this->assertTrue(empty($class->parentClasses)); + + $this->assertTrue(isset($class->fieldMappings['id'])); + $this->assertTrue(isset($class->fieldMappings['name'])); + + $this->assertEquals($class->customRepositoryClassName, "App\Reposotories\SuperRepository"); + + + $class = $this->_factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\SubclassWithRepository'); + + $this->assertTrue(empty($class->subClasses)); + $this->assertTrue(empty($class->parentClasses)); + + $this->assertTrue(isset($class->fieldMappings['id'])); + $this->assertTrue(isset($class->fieldMappings['name'])); + + $this->assertEquals($class->customRepositoryClassName, "App\Reposotories\SubRepository"); + } /** * @group DDC-388 @@ -277,4 +301,30 @@ abstract class MediumSuperclassBase extends SuperclassBase class MediumSuperclassEntity extends MediumSuperclassBase { +} + +/** + * @MappedSuperclass(repositoryClass = "App\Reposotories\SuperRepository") + */ +abstract class SuperclassBaseWithRepository +{ + /** @Id @Column(type="integer") */ + public $id; + /** @Column(type="string") */ + public $name; +} + +/** + * @Entity + */ +class SubclassWithoutRepository extends SuperclassBaseWithRepository +{ + +} +/** + * @Entity(repositoryClass = "App\Reposotories\SubRepository") + */ +class SubclassWithRepository extends SuperclassBaseWithRepository +{ + } \ No newline at end of file From b2d98495b130dbdbdff8b918b34b9643ffda3842 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Wed, 7 Sep 2011 18:29:43 -0300 Subject: [PATCH 2/6] mapping files --- .../Models/DDC869/DDC869ChequePayment.php | 32 +++++++++++++++ .../Models/DDC869/DDC869CreditCardPayment.php | 32 +++++++++++++++ .../Tests/Models/DDC869/DDC869Payment.php | 39 +++++++++++++++++++ .../Models/DDC869/DDC869PaymentRepository.php | 37 ++++++++++++++++++ .../Mapping/BasicInheritanceMappingTest.php | 22 +++++++---- ....Models.DDC869.DDC869ChequePayment.dcm.xml | 11 ++++++ ...els.DDC869.DDC869CreditCardPayment.dcm.xml | 11 ++++++ ....Tests.Models.DDC869.DDC869Payment.dcm.xml | 15 +++++++ ....Models.DDC869.DDC869ChequePayment.dcm.yml | 5 +++ ...els.DDC869.DDC869CreditCardPayment.dcm.yml | 5 +++ ....Tests.Models.DDC869.DDC869Payment.dcm.yml | 12 ++++++ 11 files changed, 214 insertions(+), 7 deletions(-) create mode 100644 tests/Doctrine/Tests/Models/DDC869/DDC869ChequePayment.php create mode 100644 tests/Doctrine/Tests/Models/DDC869/DDC869CreditCardPayment.php create mode 100644 tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php create mode 100644 tests/Doctrine/Tests/Models/DDC869/DDC869PaymentRepository.php create mode 100644 tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.dcm.xml create mode 100644 tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.dcm.xml create mode 100644 tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869Payment.dcm.xml create mode 100644 tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.dcm.yml create mode 100644 tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.dcm.yml create mode 100644 tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC869.DDC869Payment.dcm.yml diff --git a/tests/Doctrine/Tests/Models/DDC869/DDC869ChequePayment.php b/tests/Doctrine/Tests/Models/DDC869/DDC869ChequePayment.php new file mode 100644 index 000000000..32cac8c06 --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC869/DDC869ChequePayment.php @@ -0,0 +1,32 @@ +. + */ + +namespace Doctrine\Tests\Models\DDC869; + +/** + * @Entity + */ +class DDC869ChequePayment extends DDC869Payment +{ + + /** @column(type="string") */ + protected $serialNumber; + +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/Models/DDC869/DDC869CreditCardPayment.php b/tests/Doctrine/Tests/Models/DDC869/DDC869CreditCardPayment.php new file mode 100644 index 000000000..5cb32f6df --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC869/DDC869CreditCardPayment.php @@ -0,0 +1,32 @@ +. + */ + +namespace Doctrine\Tests\Models\DDC869; + +/** + * @Entity + */ +class DDC869CreditCardPayment extends DDC869Payment +{ + + /** @column(type="string") */ + protected $creditCardNumber; + +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php b/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php new file mode 100644 index 000000000..e64215ad3 --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php @@ -0,0 +1,39 @@ +. + */ + +namespace Doctrine\Tests\Models\DDC869; + +/** + * @MappedSuperclass(repositoryClass = "Doctrine\Tests\Models\DDC869\DDC869PaymentRepository") + */ +class DDC869Payment +{ + + /** + * @Id + * @Column(type="integer") + * @GeneratedValue + */ + private $id; + + /** @column(type="float") */ + protected $value; + +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/Models/DDC869/DDC869PaymentRepository.php b/tests/Doctrine/Tests/Models/DDC869/DDC869PaymentRepository.php new file mode 100644 index 000000000..d9018266a --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC869/DDC869PaymentRepository.php @@ -0,0 +1,37 @@ +. + */ + +namespace Doctrine\Tests\Models\DDC869; + +use Doctrine\ORM\EntityRepository; + +class DDC869PaymentRepository extends EntityRepository +{ + + /** + * Very complex method + * + * @return bool + */ + public function isTrue() + { + return true; + } +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php index e5fa6d220..c7330283e 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php @@ -59,22 +59,30 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase $this->assertTrue(empty($class->subClasses)); $this->assertTrue(empty($class->parentClasses)); - - $this->assertTrue(isset($class->fieldMappings['id'])); - $this->assertTrue(isset($class->fieldMappings['name'])); - $this->assertEquals($class->customRepositoryClassName, "App\Reposotories\SuperRepository"); $class = $this->_factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\SubclassWithRepository'); $this->assertTrue(empty($class->subClasses)); - $this->assertTrue(empty($class->parentClasses)); + $this->assertTrue(isset($class->fieldMappings['name'])); + $this->assertEquals($class->customRepositoryClassName, "App\Reposotories\SubRepository"); + + + $class = $this->_factory->getMetadataFor('Doctrine\Tests\Models\DDC869\DDC869CreditCardPayment'); $this->assertTrue(isset($class->fieldMappings['id'])); - $this->assertTrue(isset($class->fieldMappings['name'])); + $this->assertTrue(isset($class->fieldMappings['value'])); + $this->assertTrue(isset($class->fieldMappings['creditCardNumber'])); + $this->assertEquals($class->customRepositoryClassName, "Doctrine\Tests\Models\DDC869\DDC869PaymentRepository"); - $this->assertEquals($class->customRepositoryClassName, "App\Reposotories\SubRepository"); + + $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->assertEquals($class->customRepositoryClassName, "Doctrine\Tests\Models\DDC869\DDC869PaymentRepository"); } /** diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.dcm.xml new file mode 100644 index 000000000..0776304be --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.dcm.xml @@ -0,0 +1,11 @@ + + + + + + + + \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.dcm.xml new file mode 100644 index 000000000..daf01f034 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.dcm.xml @@ -0,0 +1,11 @@ + + + + + + + + \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869Payment.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869Payment.dcm.xml new file mode 100644 index 000000000..be9f760b9 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869Payment.dcm.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.dcm.yml new file mode 100644 index 000000000..94f269817 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.dcm.yml @@ -0,0 +1,5 @@ +Doctrine\Tests\Models\DDC869\DDC869ChequePayment: + type: entity + fields: + serialNumber: + type: string \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.dcm.yml new file mode 100644 index 000000000..153a99fa7 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.dcm.yml @@ -0,0 +1,5 @@ +Doctrine\Tests\Models\DDC869\DDC869CreditCardPayment: + type: entity + fields: + creditCardNumber: + type: string \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC869.DDC869Payment.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC869.DDC869Payment.dcm.yml new file mode 100644 index 000000000..b776664e1 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC869.DDC869Payment.dcm.yml @@ -0,0 +1,12 @@ +Doctrine\Tests\Models\DDC869\DDC869Payment: + type: mappedSuperclass + repositoryClass : Doctrine\Tests\Models\DDC869\DDC869PaymentRepository + id: + id: + type: integer + unsigned: true + generator: + strategy: AUTO + fields: + value: + type: float \ No newline at end of file From 54a53b1d03c5eb0055e0b48d558bab71c7ab6ffa Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Thu, 8 Sep 2011 11:56:05 -0300 Subject: [PATCH 3/6] tests for DDC-869 --- .../ORM/Mapping/AbstractMappingDriverTest.php | 40 +++++++++++++++++++ ....Models.DDC869.DDC869ChequePayment.dcm.xml | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 74e7764a9..779713a51 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -291,6 +291,46 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase $class->discriminatorColumn ); } + + /** + * @group DDC-869 + */ + public function testSuperclassWithRepository() + { + if (strpos(get_class($this), 'PHPMappingDriver') !== false) { + $this->markTestSkipped('PHP Mapping Drivers have no defaults.'); + } + + $driver = $this->_loadDriver(); + $em = $this->_getTestEntityManager(); + $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory(); + + $em->getConfiguration()->setMetadataDriverImpl($driver); + $factory->setEntityManager($em); + + + $class = $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->assertInstanceOf("Doctrine\Tests\Models\DDC869\DDC869PaymentRepository", + $em->getRepository("Doctrine\Tests\Models\DDC869\DDC869CreditCardPayment")); + $this->assertTrue($em->getRepository("Doctrine\Tests\Models\DDC869\DDC869ChequePayment")->isTrue()); + + + + $class = $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->assertEquals($class->customRepositoryClassName, "Doctrine\Tests\Models\DDC869\DDC869PaymentRepository"); + $this->assertInstanceOf("Doctrine\Tests\Models\DDC869\DDC869PaymentRepository", + $em->getRepository("Doctrine\Tests\Models\DDC869\DDC869ChequePayment")); + $this->assertTrue($em->getRepository("Doctrine\Tests\Models\DDC869\DDC869ChequePayment")->isTrue()); + } } /** diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.dcm.xml index 0776304be..05e2540ef 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.dcm.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> - + From 6a89de51e547117dfa03740c51e37235395e8ad5 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Thu, 8 Sep 2011 12:55:55 -0300 Subject: [PATCH 4/6] change tests --- .../Tests/Models/DDC869/DDC869Payment.php | 2 +- .../ORM/Mapping/AbstractMappingDriverTest.php | 2 +- .../Mapping/BasicInheritanceMappingTest.php | 47 +++++-------------- 3 files changed, 15 insertions(+), 36 deletions(-) diff --git a/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php b/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php index e64215ad3..7c4cfc975 100644 --- a/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php +++ b/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php @@ -31,7 +31,7 @@ class DDC869Payment * @Column(type="integer") * @GeneratedValue */ - private $id; + protected $id; /** @column(type="float") */ protected $value; diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 779713a51..0094c1b79 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -295,7 +295,7 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase /** * @group DDC-869 */ - public function testSuperclassWithRepository() + public function testMappedSuperclassWithRepository() { if (strpos(get_class($this), 'PHPMappingDriver') !== false) { $this->markTestSkipped('PHP Mapping Drivers have no defaults.'); diff --git a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php index c7330283e..7d31b8586 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php @@ -53,22 +53,11 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase $this->assertTrue(isset($class->associationMappings['mappedRelated1'])); } + /** + * @group DDC-869 + */ public function testGetMetadataForSubclassWithMappedSuperclassWhithRepository() { - $class = $this->_factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\SubclassWithoutRepository'); - - $this->assertTrue(empty($class->subClasses)); - $this->assertTrue(empty($class->parentClasses)); - $this->assertEquals($class->customRepositoryClassName, "App\Reposotories\SuperRepository"); - - - $class = $this->_factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\SubclassWithRepository'); - - $this->assertTrue(empty($class->subClasses)); - $this->assertTrue(isset($class->fieldMappings['name'])); - $this->assertEquals($class->customRepositoryClassName, "App\Reposotories\SubRepository"); - - $class = $this->_factory->getMetadataFor('Doctrine\Tests\Models\DDC869\DDC869CreditCardPayment'); $this->assertTrue(isset($class->fieldMappings['id'])); @@ -83,6 +72,14 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase $this->assertTrue(isset($class->fieldMappings['value'])); $this->assertTrue(isset($class->fieldMappings['serialNumber'])); $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->assertEquals($class->customRepositoryClassName, "Doctrine\ORM\EntityRepository"); } /** @@ -312,27 +309,9 @@ class MediumSuperclassEntity extends MediumSuperclassBase } /** - * @MappedSuperclass(repositoryClass = "App\Reposotories\SuperRepository") + * @Entity(repositoryClass = "Doctrine\ORM\EntityRepository") */ -abstract class SuperclassBaseWithRepository -{ - /** @Id @Column(type="integer") */ - public $id; - /** @Column(type="string") */ - public $name; -} - -/** - * @Entity - */ -class SubclassWithoutRepository extends SuperclassBaseWithRepository -{ - -} -/** - * @Entity(repositoryClass = "App\Reposotories\SubRepository") - */ -class SubclassWithRepository extends SuperclassBaseWithRepository +class SubclassWithRepository extends \Doctrine\Tests\Models\DDC869\DDC869Payment { } \ No newline at end of file From 7f0275155d92ac68a81cf4fafd42fe5db35fca26 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Thu, 8 Sep 2011 13:17:53 -0300 Subject: [PATCH 5/6] php mapping --- .../ORM/Mapping/Driver/AnnotationDriver.php | 3 +-- .../Tests/Models/DDC869/DDC869ChequePayment.php | 8 ++++++++ .../Models/DDC869/DDC869CreditCardPayment.php | 8 ++++++++ .../Tests/Models/DDC869/DDC869Payment.php | 17 +++++++++++++++++ .../ORM/Mapping/AbstractMappingDriverTest.php | 4 ---- ....Tests.Models.DDC869.DDC869ChequePayment.php | 5 +++++ ...ts.Models.DDC869.DDC869CreditCardPayment.php | 5 +++++ ...ctrine.Tests.Models.DDC869.DDC869Payment.php | 16 ++++++++++++++++ 8 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.php create mode 100644 tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.php create mode 100644 tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869Payment.php diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index afb89f083..36e3dcb01 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -147,10 +147,9 @@ class AnnotationDriver implements Driver // Evaluate Entity annotation if (isset($classAnnotations['Doctrine\ORM\Mapping\Entity'])) { $entityAnnot = $classAnnotations['Doctrine\ORM\Mapping\Entity']; - if($entityAnnot->repositoryClass !== null) { + if ($entityAnnot->repositoryClass !== null) { $metadata->setCustomRepositoryClass($entityAnnot->repositoryClass); } - if ($entityAnnot->readOnly) { $metadata->markReadOnly(); } diff --git a/tests/Doctrine/Tests/Models/DDC869/DDC869ChequePayment.php b/tests/Doctrine/Tests/Models/DDC869/DDC869ChequePayment.php index 32cac8c06..46cceb4c7 100644 --- a/tests/Doctrine/Tests/Models/DDC869/DDC869ChequePayment.php +++ b/tests/Doctrine/Tests/Models/DDC869/DDC869ChequePayment.php @@ -28,5 +28,13 @@ class DDC869ChequePayment extends DDC869Payment /** @column(type="string") */ protected $serialNumber; + + public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) + { + $metadata->mapField(array( + 'fieldName' => 'serialNumber', + 'type' => 'string', + )); + } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/Models/DDC869/DDC869CreditCardPayment.php b/tests/Doctrine/Tests/Models/DDC869/DDC869CreditCardPayment.php index 5cb32f6df..b446e059a 100644 --- a/tests/Doctrine/Tests/Models/DDC869/DDC869CreditCardPayment.php +++ b/tests/Doctrine/Tests/Models/DDC869/DDC869CreditCardPayment.php @@ -28,5 +28,13 @@ class DDC869CreditCardPayment extends DDC869Payment /** @column(type="string") */ protected $creditCardNumber; + + public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) + { + $metadata->mapField(array( + 'fieldName' => 'creditCardNumber', + 'type' => 'string', + )); + } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php b/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php index 7c4cfc975..0ea0b6907 100644 --- a/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php +++ b/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php @@ -35,5 +35,22 @@ class DDC869Payment /** @column(type="float") */ protected $value; + + + public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) + { + $metadata->mapField(array( + 'id' => true, + 'fieldName' => 'id', + 'type' => 'integer', + 'columnName' => 'id', + )); + $metadata->mapField(array( + 'fieldName' => 'value', + 'type' => 'float', + )); + $metadata->setCustomRepositoryClass("Doctrine\Tests\Models\DDC869\DDC869PaymentRepository"); + $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadataInfo::GENERATOR_TYPE_AUTO); + } } \ 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 0094c1b79..98c43a5b9 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -297,10 +297,6 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase */ public function testMappedSuperclassWithRepository() { - if (strpos(get_class($this), 'PHPMappingDriver') !== false) { - $this->markTestSkipped('PHP Mapping Drivers have no defaults.'); - } - $driver = $this->_loadDriver(); $em = $this->_getTestEntityManager(); $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory(); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.php new file mode 100644 index 000000000..ad8b86d9e --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869ChequePayment.php @@ -0,0 +1,5 @@ +mapField(array( + 'fieldName' => 'serialNumber', + 'type' => 'string', +)); \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.php new file mode 100644 index 000000000..1318333a8 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869CreditCardPayment.php @@ -0,0 +1,5 @@ +mapField(array( + 'fieldName' => 'creditCardNumber', + 'type' => 'string', +)); \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869Payment.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869Payment.php new file mode 100644 index 000000000..7ea84e40b --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869Payment.php @@ -0,0 +1,16 @@ +mapField(array( + 'id' => true, + 'fieldName' => 'id', + 'type' => 'integer', + 'columnName' => 'id', +)); +$metadata->mapField(array( + 'fieldName' => 'value', + 'type' => 'float', + )); +$metadata->setCustomRepositoryClass("Doctrine\Tests\Models\DDC869\DDC869PaymentRepository"); +$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); \ No newline at end of file From 19d0887bb020bc5296c2822af7f6f21651c38946 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Thu, 8 Sep 2011 13:41:16 -0300 Subject: [PATCH 6/6] check if parent class is a mapped superclass --- lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php | 4 +++- tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php | 3 ++- .../php/Doctrine.Tests.Models.DDC869.DDC869Payment.php | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 44f8641ff..cef558496 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -274,7 +274,9 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface $class->setDiscriminatorMap($parent->discriminatorMap); $class->setLifecycleCallbacks($parent->lifecycleCallbacks); $class->setChangeTrackingPolicy($parent->changeTrackingPolicy); - $class->setCustomRepositoryClass($parent->customRepositoryClassName); + if ($parent->isMappedSuperclass) { + $class->setCustomRepositoryClass($parent->customRepositoryClassName); + } } // Invoke driver diff --git a/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php b/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php index 0ea0b6907..c3c365715 100644 --- a/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php +++ b/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php @@ -48,7 +48,8 @@ class DDC869Payment $metadata->mapField(array( 'fieldName' => 'value', 'type' => 'float', - )); + )); + $metadata->isMappedSuperclass = true; $metadata->setCustomRepositoryClass("Doctrine\Tests\Models\DDC869\DDC869PaymentRepository"); $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadataInfo::GENERATOR_TYPE_AUTO); } diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869Payment.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869Payment.php index 7ea84e40b..1d1f551ba 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869Payment.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.DDC869.DDC869Payment.php @@ -12,5 +12,6 @@ $metadata->mapField(array( 'fieldName' => 'value', 'type' => 'float', )); +$metadata->isMappedSuperclass = true; $metadata->setCustomRepositoryClass("Doctrine\Tests\Models\DDC869\DDC869PaymentRepository"); $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); \ No newline at end of file