Skip to content

Commit

Permalink
[Serializer] Refactor tests to not extends ObjectNormalizer
Browse files Browse the repository at this point in the history
  • Loading branch information
lyrixx committed Jun 21, 2023
1 parent 4d46506 commit 1d238ee
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
21 changes: 21 additions & 0 deletions Tests/Normalizer/AbstractObjectNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,27 @@ public function testNormalizeUsesContextAttributeForProperties()

$this->assertSame(['propertyWithoutNullSkipNullValues' => 'foo'], $data);
}

public function testDefaultExcludeFromCacheKey()
{
$object = new DummyChild();
$object->bar = 'not called';

$normalizer = new class(null, null, null, null, null, [AbstractObjectNormalizer::EXCLUDE_FROM_CACHE_KEY => ['foo']]) extends AbstractObjectNormalizerDummy {
public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
{
AbstractObjectNormalizerTest::assertContains('foo', $this->defaultContext[ObjectNormalizer::EXCLUDE_FROM_CACHE_KEY]);
$data->bar = 'called';

return true;
}
};

$serializer = new Serializer([$normalizer]);
$serializer->normalize($object);

$this->assertSame('called', $object->bar);
}
}

class AbstractObjectNormalizerDummy extends AbstractObjectNormalizer
Expand Down
13 changes: 0 additions & 13 deletions Tests/Normalizer/ObjectNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -680,19 +680,6 @@ public function testNormalizeNotSerializableContext()
}]));
}

public function testDefaultExcludeFromCacheKey()
{
$normalizer = new class(null, null, null, null, null, null, [ObjectNormalizer::EXCLUDE_FROM_CACHE_KEY => ['foo']]) extends ObjectNormalizer {
protected function isCircularReference($object, &$context): bool
{
ObjectNormalizerTest::assertContains('foo', $this->defaultContext[ObjectNormalizer::EXCLUDE_FROM_CACHE_KEY]);

return false;
}
};
$normalizer->normalize(new ObjectDummy());
}

public function testThrowUnexpectedValueException()
{
$this->expectException(UnexpectedValueException::class);
Expand Down

0 comments on commit 1d238ee

Please sign in to comment.