Skip to content

Commit b725ddd

Browse files
Merge branch '3.1'
* 3.1: [travis] Don't use parallel on HHVM [HttpKernel] Fix RequestDataCollector starting the session [appveyor] Ignore STATUS_HEAP_CORRUPTION errors on Windows [FrameworkBundle] Skip redis cache pools test on failed connection Fixed forwarded request data in templates [Security] Fix DebugAccessDecisionManager when object is not a scalar Skip some tests on HHVM due to a PHPunit bug Use the Trusty Travis infrastructure for HHVM builds LdapUserProvider: add missing argument type doc Fixed issue with missing argument in the abstract service definition for the ldap user provider Add 3.1 to PR template branch row, remove 2.3 Improve memory efficiency [Console] Fix BC break introduced by #18101 document method name changes in Voter class add missing hint for vote() argument type [#18838] add a test to avoid regressions bumped Symfony version to 3.1.1 updated VERSION for 3.1.0 updated CHANGELOG for 3.1.0 Conflicts: src/Symfony/Component/HttpKernel/Kernel.php
2 parents aaf180e + 27827eb commit b725ddd

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Tests/Normalizer/ObjectNormalizerTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,28 @@ public function testRejectInvalidType()
545545

546546
$serializer->denormalize(array('date' => 'foo'), ObjectOuter::class);
547547
}
548+
549+
public function testExtractAttributesRespectsFormat()
550+
{
551+
$normalizer = new FormatAndContextAwareNormalizer();
552+
553+
$data = new ObjectDummy();
554+
$data->setFoo('bar');
555+
$data->bar = 'foo';
556+
557+
$this->assertSame(array('foo' => 'bar', 'bar' => 'foo'), $normalizer->normalize($data, 'foo_and_bar_included'));
558+
}
559+
560+
public function testExtractAttributesRespectsContext()
561+
{
562+
$normalizer = new FormatAndContextAwareNormalizer();
563+
564+
$data = new ObjectDummy();
565+
$data->setFoo('bar');
566+
$data->bar = 'foo';
567+
568+
$this->assertSame(array('foo' => 'bar', 'bar' => 'foo'), $normalizer->normalize($data, null, array('include_foo_and_bar' => true)));
569+
}
548570
}
549571

550572
class ObjectDummy
@@ -744,3 +766,19 @@ class ObjectInner
744766
public $foo;
745767
public $bar;
746768
}
769+
770+
class FormatAndContextAwareNormalizer extends ObjectNormalizer
771+
{
772+
protected function isAllowedAttribute($classOrObject, $attribute, $format = null, array $context = array())
773+
{
774+
if (in_array($attribute, array('foo', 'bar')) && 'foo_and_bar_included' === $format) {
775+
return true;
776+
}
777+
778+
if (in_array($attribute, array('foo', 'bar')) && isset($context['include_foo_and_bar']) && true === $context['include_foo_and_bar']) {
779+
return true;
780+
}
781+
782+
return false;
783+
}
784+
}

0 commit comments

Comments
 (0)