-
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.1.x: Using an integer as discriminator value with ORM v3 Using an integer as discriminator value with ORM v3 Bump ramsey/composer-install from 2 to 3 (#11442) Use ramsey/composer-install in PHPBench workflow (#11444) Bump doctrine/.github from 3.0.0 to 5.0.1 Upgrade codecov/codecov-action Setup Dependabot
- Loading branch information
Showing
9 changed files
with
190 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" | ||
labels: | ||
- "CI" | ||
target-branch: "2.19.x" |
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
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
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
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,157 @@ | ||
<?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); | ||
} | ||
|
||
public static function dqlStatementsForInstanceOf(): Generator | ||
{ | ||
yield [IntegerBaseClass::class, IntegerFooEntity::class]; | ||
yield [StringBaseClass::class, StringFooEntity::class]; | ||
yield [StringAsIntBaseClass::class, StringAsIntFooEntity::class]; | ||
} | ||
|
||
/** | ||
* @psalm-param class-string $baseClass | ||
* @psalm-param class-string $inheritedClass | ||
*/ | ||
#[DataProvider('dqlStatementsForInstanceOf')] | ||
public function testInstanceOf(string $baseClass, string $inheritedClass): void | ||
{ | ||
$this->_em->persist(new $inheritedClass()); | ||
$this->_em->flush(); | ||
|
||
$dql = 'SELECT p FROM ' . $baseClass . ' p WHERE p INSTANCE OF ' . $baseClass; | ||
|
||
$query = $this->_em->createQuery($dql); | ||
$result = $query->getResult(); | ||
|
||
self::assertCount(1, $result); | ||
self::assertContainsOnlyInstancesOf($baseClass, $result); | ||
} | ||
} | ||
|
||
#[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 | ||
{ | ||
} |