8000 [Serializer] Refactor tests to not extends ObjectNormalize · symfony/symfony@a732d8f · GitHub
[go: up one dir, main page]

Skip to content

Commit a732d8f

Browse files
committed
[Serializer] Refactor tests to not extends ObjectNormalize
1 parent 42437ee commit a732d8f

File tree

6 files changed

+25
-53
lines changed

6 files changed

+25
-53
lines changed

src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,5 @@ public function supportsNormalization(mixed $data, string $format = null /* , ar
6666
*
6767
* @return array<class-string|'*'|'object'|string, bool|null>
6868
*/
69-
/* public function getSupportedTypes(?string $format): array; */
69+
public function getSupportedTypes(?string $format): array;
7070
}

src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ private function createXmlEncoderWithDateTimeNormalizer(): XmlEncoder
934934

935935
private function createMockDateTimeNormalizer(): MockObject&NormalizerInterface
936936
{
937-
$mock = $this->createMock(CustomNormalizer::class);
937+
$mock = $this->createMock(NormalizerInterface::class);
938938

939939
$mock
940940
->expects($this->once())

src/Symfony/Component/Serializer/Tests/Fixtures/FormatAndContextAwareNormalizer.php

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,27 @@ public function testNormalizeUsesContextAttributeForProperties()
724724

725725
$this->assertSame(['propertyWithoutNullSkipNullValues' => 'foo'], $data);
726726
}
727+
728+
public function testDefaultExcludeFromCacheKey()
729+
{
730+
$object = new DummyChild();
731+
$object->bar = 'not called';
732+
733+
$normalizer = new class(null, null, null, null, null, [AbstractObjectNormalizer::EXCLUDE_FROM_CACHE_KEY => ['foo']]) extends AbstractObjectNormalizerDummy {
734+
public function supportsNormalization(mixed $data, string $format = null, array $context = []) : bool
735+
{
736+
AbstractObjectNormalizerTest::assertContains('foo', $this->defaultContext[ObjectNormalizer::EXCLUDE_FROM_CACHE_KEY]);
737+
$data->bar = 'called';
738+
739+
return true;
740+
}
741+
};
742+
743+
$serializer = new Serializer([$normalizer]);
744+
$serializer->normalize($object);
745+
746+
$this->assertSame('called', $object->bar);
747+
}
727748
}
728749

729750
class AbstractObjectNormalizerDummy extends AbstractObjectNormalizer

src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -680,19 +680,6 @@ public function testNormalizeNotSerializableContext()
680680
}]));
681681
}
682682

683-
public function testDefaultExcludeFromCacheKey()
684-
{
685-
$normalizer = new class(null, null, null, null, null, null, [ObjectNormalizer::EXCLUDE_FROM_CACHE_KEY => ['foo']]) extends ObjectNormalizer {
686-
protected function isCircularReference($object, &$context): bool
687-
{
688-
ObjectNormalizerTest::assertContains('foo', $this->defaultContext[ObjectNormalizer::EXCLUDE_FROM_CACHE_KEY]);
689-
690-
return false;
691-
}
692-
};
693-
$normalizer->normalize(new ObjectDummy());
694-
}
695-
696683
public function testThrowUnexpectedValueException()
697684
{
698685
$this->expectException(UnexpectedValueException::class);
@@ -744,20 +731,6 @@ public function testDoesntHaveIssuesWithUnionConstTypes()
744731
})::class)->foo);
745732
}
746733

747-
/**
748-
* @group legacy
749-
*/
750-
public function testExtractAttributesRespectsFormat()
751-
{
752-
$normalizer = new FormatAndContextAwareNormalizer();
753-
754-
$data = new ObjectDummy();
755-
$data->setFoo('bar');
756-
$data->bar = 'foo';
757-
758-
$this->assertSame(['foo' => 'bar', 'bar' => 'foo'], $normalizer->normalize($data, 'foo_and_bar_included'));
759-
}
760-
761734
public function testExtractAttributesRespectsContext()
762735
{
763736
$normalizer = new ObjectNormalizer();

src/Symfony/Component/Serializer/Tests/SerializerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function testItThrowsExceptionOnInvalidEncoder()
8989
public function testNormalizeNoMatch()
9090
{
9191
$this->expectException(UnexpectedValueException::class);
92-
$serializer = new Serializer([$this->createMock(CustomNormalizer::class)]);
92+
$serializer = new Serializer([$this->createMock(NormalizerInterface::class)]);
9393
$serializer->normalize(new \stdClass(), 'xml');
9494
}
9595

@@ -117,7 +117,7 @@ public function testNormalizeOnDenormalizer()
117117
public function testDenormalizeNoMatch()
118118
{
119119
$this->expectException(UnexpectedValueException::class);
120-
$serializer = new Serializer([$this->createMock(CustomNormalizer::class)]);
120+
$serializer = new Serializer([$this->createMock(NormalizerInterface::class)]);
121121
$serializer->denormalize('foo', 'stdClass');
122122
}
123123

0 commit comments

Comments
 (0)
0