-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
3 Variants (int, string, string in description, but int the list) of …
…discriminator with tests.
- Loading branch information
1 parent
be803ad
commit 0097839
Showing
2 changed files
with
138 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
use Generator; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
|
||
class GH11341Test extends OrmFunctionalTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->setUpEntitySchema([ | ||
IntegerBaseClass::class, | ||
IntegerFooEntity::class, | ||
IntegerBarEntity::class, | ||
StringAsIntBaseClass::class, | ||
StringAsIntFooEntity::class, | ||
StringAsIntBarEntity::class, | ||
StringBaseClass::class, | ||
StringFooEntity::class, | ||
StringBarEntity::class, | ||
]); | ||
} | ||
|
||
public static function dqlStatements(): Generator | ||
{ | ||
yield ['SELECT e FROM ' . IntegerBaseClass::class . ' e', '/WHERE [a-z]0_.type IN \(1, 2\)$/']; | ||
yield ['SELECT e FROM ' . IntegerFooEntity::class . ' e', '/WHERE [a-z]0_.type IN \(1\)$/']; | ||
yield ['SELECT e FROM ' . IntegerBarEntity::class . ' e', '/WHERE [a-z]0_.type IN \(2\)$/']; | ||
yield ['SELECT e FROM ' . StringAsIntBaseClass::class . ' e', '/WHERE [a-z]0_.type IN \(\'1\', \'2\'\)$/']; | ||
yield ['SELECT e FROM ' . StringAsIntFooEntity::class . ' e', '/WHERE [a-z]0_.type IN \(\'1\'\)$/']; | ||
yield ['SELECT e FROM ' . StringAsIntBarEntity::class . ' e', '/WHERE [a-z]0_.type IN \(\'2\'\)$/']; | ||
yield ['SELECT e FROM ' . StringBaseClass::class . ' e', '/WHERE [a-z]0_.type IN \(\'1\', \'2\'\)$/']; | ||
yield ['SELECT e FROM ' . StringFooEntity::class . ' e', '/WHERE [a-z]0_.type IN \(\'1\'\)$/']; | ||
yield ['SELECT e FROM ' . StringBarEntity::class . ' e', '/WHERE [a-z]0_.type IN \(\'2\'\)$/']; | ||
} | ||
|
||
#[DataProvider('dqlStatements')] | ||
public function testDiscriminatorValue(string $dql, string $expectedDiscriminatorValues): void | ||
{ | ||
$query = $this->_em->createQuery($dql); | ||
$sql = $query->getSQL(); | ||
|
||
self::assertMatchesRegularExpression($expectedDiscriminatorValues, $sql); | ||
} | ||
} | ||
|
||
#[ORM\Entity] | ||
#[ORM\Table(name: 'integer_discriminator')] | ||
#[ORM\InheritanceType('SINGLE_TABLE')] | ||
#[ORM\DiscriminatorColumn(name: 'type', type: 'integer')] | ||
#[ORM\DiscriminatorMap([ | ||
1 => IntegerFooEntity::class, | ||
2 => IntegerBarEntity::class, | ||
])] | ||
class IntegerBaseClass | ||
{ | ||
#[ORM\Id] | ||
#[ORM\GeneratedValue(strategy: 'IDENTITY')] | ||
#[ORM\Column(type: 'integer')] | ||
private int|null $id = null; | ||
} | ||
|
||
#[ORM\Entity] | ||
class IntegerFooEntity extends IntegerBaseClass | ||
{ | ||
} | ||
|
||
#[ORM\Entity] | ||
class IntegerBarEntity extends IntegerBaseClass | ||
{ | ||
} | ||
|
||
#[ORM\Entity] | ||
#[ORM\Table(name: 'string_as_int_discriminator')] | ||
#[ORM\InheritanceType('SINGLE_TABLE')] | ||
#[ORM\DiscriminatorColumn(name: 'type', type: 'string')] | ||
#[ORM\DiscriminatorMap([ | ||
1 => StringAsIntFooEntity::class, | ||
2 => StringAsIntBarEntity::class, | ||
])] | ||
class StringAsIntBaseClass | ||
{ | ||
#[ORM\Id] | ||
#[ORM\GeneratedValue(strategy: 'IDENTITY')] | ||
#[ORM\Column(type: 'integer')] | ||
private int|null $id = null; | ||
} | ||
|
||
#[ORM\Entity] | ||
class StringAsIntFooEntity extends StringAsIntBaseClass | ||
{ | ||
} | ||
|
||
#[ORM\Entity] | ||
class StringAsIntBarEntity extends StringAsIntBaseClass | ||
{ | ||
} | ||
|
||
|
||
#[ORM\Entity] | ||
#[ORM\Table(name: 'string_discriminator')] | ||
#[ORM\InheritanceType('SINGLE_TABLE')] | ||
#[ORM\DiscriminatorColumn(name: 'type', type: 'string')] | ||
#[ORM\DiscriminatorMap([ | ||
1 => StringFooEntity::class, | ||
2 => StringBarEntity::class, | ||
])] | ||
class StringBaseClass | ||
{ | ||
#[ORM\Id] | ||
#[ORM\GeneratedValue(strategy: 'IDENTITY')] | ||
#[ORM\Column(type: 'integer')] | ||
private int|null $id = null; | ||
} | ||
|
||
#[ORM\Entity] | ||
class StringFooEntity extends StringBaseClass | ||
{ | ||
} | ||
|
||
#[ORM\Entity] | ||
class StringBarEntity extends StringBaseClass | ||
{ | ||
} |