Refactor entity check logic in test assertions.

Replaced the usage of `$em->contains` with a more generic `is_object` and `method_exists` check for `getId`. This improves test flexibility and removes reliance on the EntityManager in these cases.
This commit is contained in:
Julien Fastré 2025-04-08 14:42:40 +02:00
parent 694b1f3c1f
commit 7c239eaf6a
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
2 changed files with 2 additions and 3 deletions

View File

@ -289,7 +289,6 @@ abstract class AbstractAggregatorTest extends KernelTestCase
public function testDataNormalization(array $data, int $version, array $customAssert): void
{
$aggregator = $this->getAggregator();
$em = $this->getContainer()->get(EntityManagerInterface::class);
$normalized = $aggregator->normalizeFormData($data);
$actual = $aggregator->denormalizeFormData($normalized, $version);
@ -300,7 +299,7 @@ abstract class AbstractAggregatorTest extends KernelTestCase
self::assertArrayHasKey($key, $actual);
if (array_key_exists($key, $customAssert)) {
call_user_func($customAssert[$key], $actual[$key], $value);
} elseif ($em->contains($value)) {
} elseif (is_object($value) && method_exists($value, 'getId')) {
self::assertEquals($value->getId(), $actual[$key]->getId());
} else {
self::assertEquals($value, $actual[$key]);

View File

@ -163,7 +163,7 @@ abstract class AbstractFilterTest extends KernelTestCase
self::assertArrayHasKey($key, $actual);
if (array_key_exists($key, $customAssert)) {
call_user_func($customAssert[$key], $actual[$key], $value);
} elseif ($em->contains($value)) {
} elseif (is_object($value) && method_exists($value, 'getId')) {
self::assertEquals($value->getId(), $actual[$key]->getId());
} else {
self::assertEquals($value, $actual[$key]);