-
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.
Merge pull request #11018 from stof/fix_result_set_builder_enum
Fix the support for enum types in the ResultSetMappingBuilder
- Loading branch information
Showing
4 changed files
with
94 additions
and
0 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
29 changes: 29 additions & 0 deletions
29
tests/Doctrine/Tests/ORM/Functional/Ticket/GH11017/GH11017Entity.php
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,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\GH11017; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity | ||
*/ | ||
class GH11017Entity | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\GeneratedValue | ||
* @ORM\Column(type="integer") | ||
* | ||
* @var ?int | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @ORM\Column(type="string", enumType=GH11017Enum::class) | ||
* | ||
* @var GH11017Enum | ||
*/ | ||
public $field; | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/Doctrine/Tests/ORM/Functional/Ticket/GH11017/GH11017Enum.php
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,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\GH11017; | ||
|
||
enum GH11017Enum: string | ||
{ | ||
case FIRST = 'first'; | ||
case SECOND = 'second'; | ||
} |
49 changes: 49 additions & 0 deletions
49
tests/Doctrine/Tests/ORM/Functional/Ticket/GH11017/GH11017Test.php
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,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\GH11017; | ||
|
||
use Doctrine\ORM\AbstractQuery; | ||
use Doctrine\ORM\Query\ResultSetMappingBuilder; | ||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
|
||
use function sprintf; | ||
|
||
/** | ||
* @requires PHP 8.1 | ||
*/ | ||
class GH11017Test extends OrmFunctionalTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->setUpEntitySchema([ | ||
GH11017Entity::class, | ||
]); | ||
} | ||
|
||
public function testPostPersistListenerUpdatingObjectFieldWhileOtherInsertPending(): void | ||
{ | ||
$entity1 = new GH11017Entity(); | ||
$entity1->field = GH11017Enum::FIRST; | ||
$this->_em->persist($entity1); | ||
|
||
$this->_em->flush(); | ||
$this->_em->clear(); | ||
|
||
$rsm = new ResultSetMappingBuilder($this->_em, ResultSetMappingBuilder::COLUMN_RENAMING_INCREMENT); | ||
$rsm->addRootEntityFromClassMetadata(GH11017Entity::class, 'e'); | ||
|
||
$tableName = $this->_em->getClassMetadata(GH11017Entity::class)->getTableName(); | ||
$sql = sprintf('SELECT %s FROM %s e WHERE id = :id', $rsm->generateSelectClause(), $tableName); | ||
|
||
$query = $this->_em->createNativeQuery($sql, $rsm) | ||
->setParameter('id', $entity1->id); | ||
|
||
$entity1Reloaded = $query->getSingleResult(AbstractQuery::HYDRATE_ARRAY); | ||
self::assertNotNull($entity1Reloaded); | ||
self::assertSame($entity1->field, $entity1Reloaded['field']); | ||
} | ||
} |