mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
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:
parent
694b1f3c1f
commit
7c239eaf6a
@ -289,7 +289,6 @@ abstract class AbstractAggregatorTest extends KernelTestCase
|
|||||||
public function testDataNormalization(array $data, int $version, array $customAssert): void
|
public function testDataNormalization(array $data, int $version, array $customAssert): void
|
||||||
{
|
{
|
||||||
$aggregator = $this->getAggregator();
|
$aggregator = $this->getAggregator();
|
||||||
$em = $this->getContainer()->get(EntityManagerInterface::class);
|
|
||||||
|
|
||||||
$normalized = $aggregator->normalizeFormData($data);
|
$normalized = $aggregator->normalizeFormData($data);
|
||||||
$actual = $aggregator->denormalizeFormData($normalized, $version);
|
$actual = $aggregator->denormalizeFormData($normalized, $version);
|
||||||
@ -300,7 +299,7 @@ abstract class AbstractAggregatorTest extends KernelTestCase
|
|||||||
self::assertArrayHasKey($key, $actual);
|
self::assertArrayHasKey($key, $actual);
|
||||||
if (array_key_exists($key, $customAssert)) {
|
if (array_key_exists($key, $customAssert)) {
|
||||||
call_user_func($customAssert[$key], $actual[$key], $value);
|
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());
|
self::assertEquals($value->getId(), $actual[$key]->getId());
|
||||||
} else {
|
} else {
|
||||||
self::assertEquals($value, $actual[$key]);
|
self::assertEquals($value, $actual[$key]);
|
||||||
|
@ -163,7 +163,7 @@ abstract class AbstractFilterTest extends KernelTestCase
|
|||||||
self::assertArrayHasKey($key, $actual);
|
self::assertArrayHasKey($key, $actual);
|
||||||
if (array_key_exists($key, $customAssert)) {
|
if (array_key_exists($key, $customAssert)) {
|
||||||
call_user_func($customAssert[$key], $actual[$key], $value);
|
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());
|
self::assertEquals($value->getId(), $actual[$key]->getId());
|
||||||
} else {
|
} else {
|
||||||
self::assertEquals($value, $actual[$key]);
|
self::assertEquals($value, $actual[$key]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user