Skip to content

Commit

Permalink
New idToEntityId() for easier testing #10547
Browse files Browse the repository at this point in the history
  • Loading branch information
PowerKiKi committed Oct 1, 2024
1 parent d41273c commit cd39834
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/Testing/Api/Input/Operator/OperatorType.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ protected function getFilteredResult(string $class, string $field, string $opera
return $qb->getQuery()->getResult();
}

/**
* Parse an ID into an EntityID.
*
* @param class-string $entity
*
* @return ($id is null ? null : EntityID)
*/
protected function idToEntityId(string $entity, ?int $id): ?EntityID
{
if ($id === null) {
return null;
}

$type = _types()->getId($entity);

return $type->parseValue($id);
}

/**
* Parse an array of ID into an array of EntityID.
*
Expand All @@ -48,13 +66,13 @@ protected function getFilteredResult(string $class, string $field, string $opera
*/
protected function idsToEntityIds(string $entity, ?array $ids): ?array
{
$type = _types()->getId($entity);
$parsed = null;
if ($ids !== null) {
$parsed = [];
foreach ($ids as $id) {
$parsed[] = $type->parseValue($id);
}
if ($ids === null) {
return null;
}

$parsed = [];
foreach ($ids as $id) {
$parsed[] = $this->idToEntityId($entity, $id);
}

return $parsed;
Expand Down

0 comments on commit cd39834

Please sign in to comment.