From 775d91c2a3de78148d75ec32d1ee3ee87e6187ab Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 5 Jul 2020 20:11:01 +0200 Subject: [PATCH] [GH-8122] Move test from AbstractMappingDriverTest to ClassMetadataFactoryTest case --- .../CaseSensitiveDiscriminatorMap/Cube.php | 10 ----- .../CaseSensitiveDiscriminatorMap/Shape.php | 44 ------------------- .../ORM/Mapping/AbstractMappingDriverTest.php | 12 ----- .../ORM/Mapping/ClassMetadataFactoryTest.php | 30 +++++++++++++ ...ls.CaseSensitiveDiscriminatorMap.Shape.php | 28 ------------ ...aseSensitiveDiscriminatorMap.Shape.dcm.xml | 15 ------- ...aseSensitiveDiscriminatorMap.Shape.dcm.yml | 14 ------ 7 files changed, 30 insertions(+), 123 deletions(-) delete mode 100644 tests/Doctrine/Tests/Models/CaseSensitiveDiscriminatorMap/Cube.php delete mode 100644 tests/Doctrine/Tests/Models/CaseSensitiveDiscriminatorMap/Shape.php delete mode 100644 tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CaseSensitiveDiscriminatorMap.Shape.php delete mode 100644 tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.CaseSensitiveDiscriminatorMap.Shape.dcm.xml delete mode 100644 tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.CaseSensitiveDiscriminatorMap.Shape.dcm.yml diff --git a/tests/Doctrine/Tests/Models/CaseSensitiveDiscriminatorMap/Cube.php b/tests/Doctrine/Tests/Models/CaseSensitiveDiscriminatorMap/Cube.php deleted file mode 100644 index 0c608f7453b..00000000000 --- a/tests/Doctrine/Tests/Models/CaseSensitiveDiscriminatorMap/Cube.php +++ /dev/null @@ -1,10 +0,0 @@ -setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_SINGLE_TABLE); - $metadata->setDiscriminatorColumn([ - 'name' => 'discr', - 'type' => 'string', - 'length' => 32, - ]); - $metadata->setDiscriminatorMap([ - 'cube' => cube::class, - ]); - $metadata->mapField([ - 'fieldName' => 'id', - 'type' => 'string', - 'length' => null, - 'precision' => 0, - 'scale' => 0, - 'nullable' => false, - 'unique' => false, - 'id' => true, - 'columnName' => 'id', - ]); - $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); - } -} diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index eb2388b9e52..f9bbe629e29 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -1080,18 +1080,6 @@ public function testDiscriminatorColumnDefaultName() $class = $this->createClassMetadata(SingleTableEntityIncompleteDiscriminatorColumnMapping::class); $this->assertEquals('dtype', $class->discriminatorColumn['name']); } - - public function testInvalidSubClassCase() - { - class_exists(CaseSensitiveDiscriminatorMap\Cube::class); - - $this->expectException(MappingException::class); - $this->expectExceptionMessage('Entity class \'Doctrine\Tests\Models\CaseSensitiveDiscriminatorMap\cube\' used in the discriminator map of class \'Doctrine\Tests\Models\CaseSensitiveDiscriminatorMap\Shape\' does not exist.'); - - $em = $this->_getTestEntityManager(); - $factory = $this->createClassMetadataFactory($em); - $factory->getMetadataFor(CaseSensitiveDiscriminatorMap\Shape::class); - } } /** diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index 35647586734..f58010fb5a7 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -453,6 +453,36 @@ public function testInheritsIdGeneratorMappingFromEmbeddable() $this->assertTrue($userMetadata->isIdGeneratorIdentity()); } + + public function testInvalidSubClassCase() + { + $this->expectException(MappingException::class); + $this->expectExceptionMessage('Entity class \'Doctrine\Tests\ORM\Mapping\cube\' used in the discriminator map of class \'Doctrine\Tests\ORM\Mapping\Shape\' does not exist.'); + + $cmf = new ClassMetadataFactory(); + $driver = $this->createAnnotationDriver([__DIR__]); + $em = $this->_createEntityManager($driver); + $cmf->setEntityManager($em); + + $userMetadata = $cmf->getMetadataFor(Shape::class); + } +} + +/** + * @Entity + * @InheritanceType("SINGLE_TABLE") + * @DiscriminatorMap({"cube" = cube::class}) + * @DiscriminatorColumn(name="discr", length=32, type="string") + */ +abstract class Shape +{ + /** @Id @Column(type="string") @GeneratedValue(strategy="AUTO") */ + public $id; +} + +/** @Entity */ +final class Cube extends Shape +{ } /* Test subject class with overridden factory method for mocking purposes */ diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CaseSensitiveDiscriminatorMap.Shape.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CaseSensitiveDiscriminatorMap.Shape.php deleted file mode 100644 index 5299f8246c9..00000000000 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CaseSensitiveDiscriminatorMap.Shape.php +++ /dev/null @@ -1,28 +0,0 @@ -setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_SINGLE_TABLE); -$metadata->setDiscriminatorColumn([ - 'name' => 'discr', - 'type' => 'string', - 'length' => 32, -]); -$metadata->setDiscriminatorMap([ - 'cube' => cube::class, -]); -$metadata->mapField([ - 'fieldName' => 'id', - 'type' => 'string', - 'length' => null, - 'precision' => 0, - 'scale' => 0, - 'nullable' => false, - 'unique' => false, - 'id' => true, - 'columnName' => 'id', -]); -$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.CaseSensitiveDiscriminatorMap.Shape.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.CaseSensitiveDiscriminatorMap.Shape.dcm.xml deleted file mode 100644 index 51139c14bc3..00000000000 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.CaseSensitiveDiscriminatorMap.Shape.dcm.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.CaseSensitiveDiscriminatorMap.Shape.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.CaseSensitiveDiscriminatorMap.Shape.dcm.yml deleted file mode 100644 index 062f9ddc99f..00000000000 --- a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.CaseSensitiveDiscriminatorMap.Shape.dcm.yml +++ /dev/null @@ -1,14 +0,0 @@ -Doctrine\Tests\Models\CaseSensitiveDiscriminatorMap\Shape: - type: entity - inheritanceType: SINGLE_TABLE - discriminatorMap: - cube: Doctrine\Tests\Models\CaseSensitiveDiscriminatorMap\cube - discriminatorColumn: - type: string - name: discr - length: 32 - id: - id: - type: integer - generator: - strategy: AUTO