Skip to content

Commit 5f29fcd

Browse files
committed
Revert "Fix EnumType not being hydrated with HYDRATE_ARRAY (#9995)"
This reverts commit bb3ce7e.
1 parent 6dd07e4 commit 5f29fcd

File tree

3 files changed

+1
-112
lines changed

3 files changed

+1
-112
lines changed

lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ protected function registerManaged(ClassMetadata $class, $entity, array $data)
692692
*
693693
* @return BackedEnum|array<BackedEnum>
694694
*/
695-
protected function buildEnum($value, string $enumType)
695+
private function buildEnum($value, string $enumType)
696696
{
697697
if (is_array($value)) {
698698
return array_map(static function ($value) use ($enumType): BackedEnum {

lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php

-34
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@ class ArrayHydrator extends AbstractHydrator
3636
/** @var int */
3737
private $_resultCounter = 0;
3838

39-
/**
40-
* The cache used during enum processing.
41-
*
42-
* @var array<string, mixed>
43-
*/
44-
private $_enumCache = [];
45-
4639
/**
4740
* {@inheritdoc}
4841
*/
@@ -83,9 +76,6 @@ protected function hydrateRowData(array $row, array &$result)
8376

8477
// 2) Now hydrate the data found in the current row.
8578
foreach ($rowData['data'] as $dqlAlias => $data) {
86-
// build enums if exists
87-
$this->processEnums($dqlAlias, $data);
88-
8979
$index = false;
9080

9181
if (isset($this->resultSetMapping()->parentAliasMap[$dqlAlias])) {
@@ -287,28 +277,4 @@ private function updateResultPointer(
287277
end($coll);
288278
$this->_resultPointers[$dqlAlias] =& $coll[key($coll)];
289279
}
290-
291-
/** @param mixed[] $data */
292-
private function processEnums(string $dqlAlias, array &$data): void
293-
{
294-
// init cache
295-
if (! isset($this->_enumCache[$dqlAlias])) {
296-
$this->_enumCache[$dqlAlias] = [];
297-
298-
$className = $this->resultSetMapping()->aliasMap[$dqlAlias];
299-
$classMetadata = $this->getClassMetadata($className);
300-
301-
foreach ($classMetadata->fieldMappings as $key => $fieldMapping) {
302-
if (isset($fieldMapping['enumType'])) {
303-
$this->_enumCache[$dqlAlias][$key] = $fieldMapping['enumType'];
304-
}
305-
}
306-
}
307-
308-
foreach ($data as $key => $value) {
309-
if (isset($this->_enumCache[$dqlAlias][$key]) && $value !== null) {
310-
$data[$key] = $this->buildEnum($value, $this->_enumCache[$dqlAlias][$key]);
311-
}
312-
}
313-
}
314280
}

tests/Doctrine/Tests/ORM/Hydration/ArrayHydratorTest.php

-77
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
use Doctrine\Tests\Models\CMS\CmsComment;
1212
use Doctrine\Tests\Models\CMS\CmsPhonenumber;
1313
use Doctrine\Tests\Models\CMS\CmsUser;
14-
use Doctrine\Tests\Models\Enums\Card;
15-
use Doctrine\Tests\Models\Enums\Suit;
1614
use Doctrine\Tests\Models\Forum\ForumBoard;
1715
use Doctrine\Tests\Models\Forum\ForumCategory;
1816

@@ -1224,79 +1222,4 @@ public function testIndexByAndMixedResult($userEntityKey): void
12241222
self::assertArrayHasKey(2, $result);
12251223
self::assertEquals(2, $result[2][$userEntityKey]['id']);
12261224
}
1227-
1228-
/**
1229-
* @requires PHP 8.1
1230-
*/
1231-
public function testArrayResultWithEnumField(): void
1232-
{
1233-
$rsm = new ResultSetMapping();
1234-
1235-
$rsm->addEntityResult(Card::class, 'c');
1236-
$rsm->addFieldResult('c', 'c__id', 'id');
1237-
$rsm->addFieldResult('c', 'c__suit', 'suit');
1238-
$rsm->addIndexBy('c', 'id');
1239-
1240-
// Faked result set
1241-
$resultSet = [
1242-
//row1
1243-
[
1244-
'c__id' => '1',
1245-
'c__suit' => 'H',
1246-
],
1247-
[
1248-
'c__id' => '2',
1249-
'c__suit' => 'D',
1250-
],
1251-
];
1252-
1253-
$stmt = ArrayResultFactory::createFromArray($resultSet);
1254-
$hydrator = new ArrayHydrator($this->entityManager);
1255-
$result = $hydrator->hydrateAll($stmt, $rsm);
1256-
1257-
self::assertCount(2, $result);
1258-
1259-
self::assertEquals(1, $result[1]['id']);
1260-
self::assertEquals(Suit::Hearts, $result[1]['suit']);
1261-
1262-
self::assertEquals(2, $result[2]['id']);
1263-
self::assertEquals(Suit::Diamonds, $result[2]['suit']);
1264-
}
1265-
1266-
/**
1267-
* @requires PHP 8.1
1268-
*/
1269-
public function testScalarResultWithEnumField(): void
1270-
{
1271-
$rsm = new ResultSetMapping();
1272-
1273-
$rsm->addEntityResult(Card::class, 'c');
1274-
$rsm->addScalarResult('c__suit', 'someAlias', 'string');
1275-
$rsm->addEnumResult('c__suit', Suit::class);
1276-
1277-
// Faked result set
1278-
$resultSet = [
1279-
//row1
1280-
[
1281-
'c__id' => '1',
1282-
'c__suit' => 'C',
1283-
],
1284-
[
1285-
'c__id' => '2',
1286-
'c__suit' => 'S',
1287-
],
1288-
];
1289-
1290-
$stmt = ArrayResultFactory::createFromArray($resultSet);
1291-
$hydrator = new ArrayHydrator($this->entityManager);
1292-
$result = $hydrator->hydrateAll($stmt, $rsm);
1293-
1294-
self::assertCount(2, $result);
1295-
1296-
self::assertCount(1, $result[0]); //assert that in each result we have only one "someAlias" field
1297-
self::assertEquals(Suit::Clubs, $result[0]['someAlias']);
1298-
1299-
self::assertCount(1, $result[1]);
1300-
self::assertEquals(Suit::Spades, $result[1]['someAlias']);
1301-
}
13021225
}

0 commit comments

Comments
 (0)