Skip to content

Commit b572bfe

Browse files
maximecolinHypeMC
authored andcommitted
Introduce testNotListedValueInEnumArray
1 parent fff085b commit b572bfe

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/Tests/ORM/Hydration/SimpleObjectHydratorTest.php

+21
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
use Doctrine\DBAL\Types\Type as DBALType;
88
use Doctrine\ORM\Internal\Hydration\HydrationException;
99
use Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator;
10+
use Doctrine\ORM\Mapping\MappingException;
1011
use Doctrine\ORM\Query\ResultSetMapping;
1112
use Doctrine\Tests\DbalTypes\GH8565EmployeePayloadType;
1213
use Doctrine\Tests\DbalTypes\GH8565ManagerPayloadType;
1314
use Doctrine\Tests\Mocks\ArrayResultFactory;
1415
use Doctrine\Tests\Models\CMS\CmsAddress;
1516
use Doctrine\Tests\Models\Company\CompanyPerson;
17+
use Doctrine\Tests\Models\Enums\Scale;
1618
use Doctrine\Tests\Models\GH8565\GH8565Employee;
1719
use Doctrine\Tests\Models\GH8565\GH8565Manager;
1820
use Doctrine\Tests\Models\GH8565\GH8565Person;
@@ -155,4 +157,23 @@ public function testWrongValuesShouldNotBeConvertedToPhpValue(): void
155157
$result = $hydrator->hydrateAll($stmt, $rsm);
156158
self::assertEquals($result[0], $expectedEntity);
157159
}
160+
161+
public function testNotListedValueInEnumArray(): void
162+
{
163+
$this->expectException(MappingException::class);
164+
$rsm = new ResultSetMapping();
165+
$rsm->addEntityResult(Scale::class, 's');
166+
$rsm->addFieldResult('s', 's__id', 'id');
167+
$rsm->addFieldResult('s', 's__supported_units', 'supportedUnits');
168+
$resultSet = [
169+
[
170+
's__id' => 1,
171+
's__supported_units' => 'g,m,unknown_case',
172+
],
173+
];
174+
175+
$stmt = ArrayResultFactory::createFromArray($resultSet);
176+
$hydrator = new SimpleObjectHydrator($this->entityManager);
177+
$hydrator->hydrateAll($stmt, $rsm);
178+
}
158179
}

0 commit comments

Comments
 (0)