Skip to content

Commit e401401

Browse files
committed
bug #2060 Fixed explicit disabling of serializer max depth checks (cezarystepkowski)
This PR was merged into the 2.7 branch. Discussion ---------- Fixed explicit disabling of serializer max depth checks JMS Serializer is configured with max depth checking enabled when method `disableMaxDepth` is called in `FOS\RestBundle\Context\Context`. This PR fixes the behaviour to actually configure serializer without max depth checking enabled in this scenario. Commits ------- 3630ed9 Fixed explicit disabling of serializer max depth checks
2 parents 989551c + 3630ed9 commit e401401

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

Serializer/JMSSerializerAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private function convertContext(Context $context, $direction)
104104
if (null !== $context->getGroups()) {
105105
$jmsContext->setGroups($context->getGroups());
106106
}
107-
if (null !== $context->getMaxDepth(false) || null !== $context->isMaxDepthEnabled()) {
107+
if (null !== $context->getMaxDepth(false) || true === $context->isMaxDepthEnabled()) {
108108
$jmsContext->enableMaxDepthChecks();
109109
}
110110
if (null !== $context->getSerializeNull()) {

Tests/Context/ContextTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@ public function testMaxDepth()
9494
$this->assertEquals(10, $this->context->getMaxDepth());
9595
}
9696

97+
public function testEnableMaxDepth()
98+
{
99+
$this->context->enableMaxDepth();
100+
101+
$this->assertTrue($this->context->isMaxDepthEnabled());
102+
}
103+
104+
public function testDisableMaxDepth()
105+
{
106+
$this->context->disableMaxDepth();
107+
108+
$this->assertFalse($this->context->isMaxDepthEnabled());
109+
}
110+
97111
public function testSerializeNull()
98112
{
99113
$this->context->setSerializeNull(true);

Tests/Serializer/JMSSerializerAdapterTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,18 @@ public function testContextInfoAreConverted()
113113

114114
$this->adapter->serialize('foo', 'json', $fosContext);
115115
}
116+
117+
public function testContextDoesNotEnableMaxDepthChecksWhenExplicitlyDisabled()
118+
{
119+
$jmsContext = $this->getMockBuilder(SerializationContext::class)->getMock();
120+
121+
$jmsContext->expects($this->never())->method('enableMaxDepthChecks');
122+
123+
$this->serializationContextFactory->method('createSerializationContext')->willReturn($jmsContext);
124+
125+
$fosContext = new Context();
126+
$fosContext->disableMaxDepth();
127+
128+
$this->adapter->serialize('foo', 'json', $fosContext);
129+
}
116130
}

0 commit comments

Comments
 (0)