mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-11-03 10:36:49 +09:00
* Align Doctrine mappings and DB connections * Refactor Doctrine timestamp handling * Migrate product lookups to Doctrine repos * Use registrar entities instead of ID fields * Migrate FK columns to Doctrine associations * Use Client relations in balance/reset entities * Document inherited id lookup in tests * Harden entity lookups and EM recovery * Fix duplicate credit invoice item recovery * Use helper for setting invoice IDs in tests
46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Copyright 2022-2026 FOSSBilling
|
|
* SPDX-License-Identifier: Apache-2.0.
|
|
*
|
|
* @copyright FOSSBilling (https://www.fossbilling.org)
|
|
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache-2.0
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Helpers;
|
|
|
|
/**
|
|
* Force the value of an entity's `id` property via reflection.
|
|
*
|
|
* Doctrine entities have private `id` properties; tests need to set them
|
|
* directly to simulate a persisted row without going through the database.
|
|
*
|
|
* Entities may be subclassed by the `createEntity` proxy helper, so the `id`
|
|
* property can live on a parent class and must be located by walking up the
|
|
* inheritance chain.
|
|
*
|
|
* @template T of object
|
|
*
|
|
* @param T $entity
|
|
*
|
|
* @return T
|
|
*/
|
|
function setEntityId(object $entity, int $id): object
|
|
{
|
|
$reflection = new \ReflectionClass($entity);
|
|
while (!$reflection->hasProperty('id')) {
|
|
$parent = $reflection->getParentClass();
|
|
if ($parent === false) {
|
|
throw new \ReflectionException(sprintf('Property %s::$id does not exist', $entity::class));
|
|
}
|
|
$reflection = $parent;
|
|
}
|
|
|
|
$reflection->getProperty('id')->setValue($entity, $id);
|
|
|
|
return $entity;
|
|
}
|