Skip to content

Commit

Permalink
Controls growing rate of the abstract test class
Browse files Browse the repository at this point in the history
  • Loading branch information
gquemener committed May 3, 2020
1 parent cad84ac commit 33a3e2d
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 51 deletions.
10 changes: 10 additions & 0 deletions tests/Doctrine/Tests/Models/CaseSensitiveDiscriminatorMap/Cube.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\Models\CaseSensitiveDiscriminatorMap;

/** @Entity */
final class Cube extends Shape
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);

namespace Doctrine\Tests\Models\CaseSensitiveDiscriminatorMap;

use Doctrine\ORM\Mapping\ClassMetadataInfo;

/**
* @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;

public static function loadMetadata(ClassMetadataInfo $metadata)
{
$metadata->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);
}
}
49 changes: 3 additions & 46 deletions tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Doctrine\ORM\Mapping\MappingException;
use Doctrine\ORM\Mapping\UnderscoreNamingStrategy;
use Doctrine\Tests\Models\Cache\City;
use Doctrine\Tests\Models\CaseSensitiveDiscriminatorMap\Shape;
use Doctrine\Tests\Models\CMS\CmsAddress;
use Doctrine\Tests\Models\CMS\CmsAddressListener;
use Doctrine\Tests\Models\CMS\CmsUser;
Expand Down Expand Up @@ -1079,12 +1080,10 @@ public function testDiscriminatorColumnDefaultName()
$this->assertEquals('dtype', $class->discriminatorColumn['name']);
}

/**
* @expectedException \Doctrine\ORM\Mapping\MappingException
* @expectedExceptionMessage Entity class 'Doctrine\Tests\ORM\Mapping\cube' used in the discriminator map of class 'Doctrine\Tests\ORM\Mapping\Shape' does not exist.
*/
public function testInvalidSubClassCase()
{
$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.');
$this->createClassMetadata(Shape::class);
}
}
Expand Down Expand Up @@ -1352,48 +1351,6 @@ public static function loadMetadata(ClassMetadataInfo $metadata)
}
}

/**
* @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;

public static function loadMetadata(ClassMetadataInfo $metadata)
{
$metadata->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);
}
}

/** @Entity */
class Cube extends Shape
{
}

/**
* @Entity
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\Tests\ORM\Mapping\cube;
use Doctrine\Tests\Models\CaseSensitiveDiscriminatorMap\cube;

/* @var $metadata ClassMetadataInfo */
$metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_SINGLE_TABLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Doctrine\Tests\ORM\Mapping\Shape" inheritance-type="SINGLE_TABLE">
<entity name="Doctrine\Tests\Models\CaseSensitiveDiscriminatorMap\Shape" inheritance-type="SINGLE_TABLE">
<discriminator-column name="discr" type="string" length="32" />
<discriminator-map>
<discriminator-mapping value="cube" class="Doctrine\Tests\ORM\Mapping\cube" />
<discriminator-mapping value="cube" class="Doctrine\Tests\Models\CaseSensitiveDiscriminatorMap\cube" />
</discriminator-map>
<id name="id" type="integer" column="id">
<generator strategy="AUTO" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Doctrine\Tests\ORM\Mapping\Shape:
Doctrine\Tests\Models\CaseSensitiveDiscriminatorMap\Shape:
type: entity
inheritanceType: SINGLE_TABLE
discriminatorMap:
cube: Doctrine\Tests\ORM\Mapping\cube
cube: Doctrine\Tests\Models\CaseSensitiveDiscriminatorMap\cube
discriminatorColumn:
type: string
name: discr
Expand Down

0 comments on commit 33a3e2d

Please sign in to comment.