Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Serializer] Refactor tests to not extends ObjectNormalizer #50735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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