Skip to content

Commit

Permalink
Introduce testNotListedValueInEnumArray
Browse files Browse the repository at this point in the history
  • Loading branch information
maximecolin authored and HypeMC committed Jan 22, 2025
1 parent fff085b commit fc3cee4
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/Tests/ORM/Hydration/SimpleObjectHydratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
use Doctrine\DBAL\Types\Type as DBALType;
use Doctrine\ORM\Internal\Hydration\HydrationException;
use Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator;
use Doctrine\ORM\Mapping\MappingException;
use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\Tests\DbalTypes\GH8565EmployeePayloadType;
use Doctrine\Tests\DbalTypes\GH8565ManagerPayloadType;
use Doctrine\Tests\Mocks\ArrayResultFactory;
use Doctrine\Tests\Models\CMS\CmsAddress;
use Doctrine\Tests\Models\Company\CompanyPerson;
use Doctrine\Tests\Models\Enums\Scale;
use Doctrine\Tests\Models\GH8565\GH8565Employee;
use Doctrine\Tests\Models\GH8565\GH8565Manager;
use Doctrine\Tests\Models\GH8565\GH8565Person;
Expand Down Expand Up @@ -155,4 +157,26 @@ public function testWrongValuesShouldNotBeConvertedToPhpValue(): void
$result = $hydrator->hydrateAll($stmt, $rsm);
self::assertEquals($result[0], $expectedEntity);
}

/**
* @requires PHP 8.1
*/
public function testNotListedValueInEnumArray(): void
{
$this->expectException(MappingException::class);
$rsm = new ResultSetMapping();
$rsm->addEntityResult(Scale::class, 's');
$rsm->addFieldResult('s', 's__id', 'id');
$rsm->addFieldResult('s', 's__supported_units', 'supportedUnits');
$resultSet = [
[
's__id' => 1,
's__supported_units' => 'g,m,unknown_case',
],
];

$stmt = ArrayResultFactory::createFromArray($resultSet);
$hydrator = new SimpleObjectHydrator($this->entityManager);
$hydrator->hydrateAll($stmt, $rsm);
}
}

0 comments on commit fc3cee4

Please sign in to comment.