10000 improved tests · symfony/symfony@ebf6254 · GitHub
[go: up one dir, main page]

Skip to content

Commit ebf6254

Browse files
committed
improved tests
1 parent 582700d commit ebf6254

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

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

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ public function testDenormalizeUntypedStringObject()
549549
$this->assertEquals('', $actual->value->value);
550550
}
551551

552-
public function testChildContextKeepsOriginalContextCacheKey()
552+
public function testProvidingContextCacheKeyGeneratesSameChildContextCacheKey()
553553
{
554554
$foobar = new Dummy();
555555
$foobar->foo = new EmptyDummy();
@@ -584,6 +584,7 @@ protected function createChildContext(array $parentContext, string $attribute, ?
584584
};
585585

586586
$serializer = new Serializer([$normalizer]);
587+
587588
$serializer->normalize($foobar, null, ['cache_key' => 'hardcoded', 'iri' => '/dummy/1']);
588589
$firstChildContextCacheKey = $normalizer->childContextCacheKey;
589590

@@ -593,6 +594,46 @@ protected function createChildContext(array $parentContext, string $attribute, ?
593594
$this->assertSame($firstChildContextCacheKey, $secondChildContextCacheKey);
594595
}
595596

597+
public function testChildContextKeepsOriginalContextCacheKey()
598+
{
599+
$foobar = new Dummy();
600+
$foobar->foo = new EmptyDummy();
601+
$foobar->bar = 'bar';
602+
$foobar->baz = 'baz';
603+
$data = [
604+
'foo' => [],
605+
'bar' => 'bar',
606+
'baz' => 'baz',
607+
];
608+
609+
$normalizer = new class() extends AbstractObjectNormalizerDummy {
610+
public $childContextCacheKey = null;
611+
612+
protected function extractAttributes(object $object, string $format = null, array $context = []): array
613+
{
614+
return array_keys((array) $object);
615+
}
616+
617+
protected function getAttributeValue(object $object, string $attribute, string $format = null, array $context = [])
618+
{
619+
return $object->{$attribute};
620+
}
621+
622+
protected function createChildContext(array $parentContext, string $attribute, ?string $format): array
623+
{
624+
$childContext = parent::createChildContext($parentContext, $attribute, $format);
625+
$this->childContextCacheKey = $childContext['cache_key'];
626+
627+
return $childContext;
628+
}
629+
};
630+
631+
$serializer = new Serializer([$normalizer]);
632+
$serializer->normalize($foobar, null, ['cache_key' => 'hardcoded', 'iri' => '/dummy/1']);
633+
634+
$this->assertSame('hardcoded-foo', $normalizer->childContextCacheKey);
635+
}
636+
596637
public function testChildContextCacheKeyStaysFalseWhenOriginalCacheKeyIsFalse()
597638
{
598639
$foobar = new Dummy();

0 commit comments

Comments
 (0)
0