/** * @param Context $context * @param int $direction {@see self} constants * * @return JMSContext */ private function convertContext(Context $context, $direction) { if ($direction === self::SERIALIZATION) { $jmsContext = JMSSerializationContext::create(); } else { $jmsContext = JMSDeserializationContext::create(); if (null !== $context->getMaxDepth()) { for ($i = 0; $i < $context->getMaxDepth(); ++$i) { $jmsContext->increaseDepth(); } } } foreach ($context->getAttributes() as $key => $value) { $jmsContext->attributes->set($key, $value); } if (null !== $context->getVersion()) { $jmsContext->setVersion($context->getVersion()); } $groups = $context->getGroups(); if (!empty($groups)) { $jmsContext->setGroups($context->getGroups()); } if (null !== $context->getMaxDepth()) { $jmsContext->enableMaxDepthChecks(); } if (null !== $context->getSerializeNull()) { $jmsContext->setSerializeNull($context->getSerializeNull()); } return $jmsContext; }
/** * @param Context $context */ private function convertContext(Context $context) { $newContext = array(); foreach ($context->getAttributes() as $key => $value) { $newContext[$key] = $value; } $newContext['groups'] = $context->getGroups(); $newContext['version'] = $context->getVersion(); $newContext['maxDepth'] = $context->getMaxDepth(); return $newContext; }
public function testApiWithoutSerializerGroups() { $this->parameterResolver->expects($this->once())->method('resolveApi')->will($this->returnValue(true)); $this->parameterResolver->expects($this->once())->method('resolveSerializerGroups')->will($this->returnValue([])); $this->parameterResolver->expects($this->once())->method('resolveSerializerNull')->will($this->returnValue($null = true)); $event = $this->createViewEventMock(); $event->expects($this->once())->method('getView')->will($this->returnValue($view = $this->createViewMock())); $event->expects($this->once())->method('getResource')->will($this->returnValue($resource = $this->createResourceMock())); $resource->expects($this->once())->method('getName')->will($this->returnValue($name = 'name')); $view->expects($this->exactly(2))->method('getContext')->will($this->returnValue($context = new Context())); $this->subscriber->onApi($event); $this->assertSame([GroupsExclusionStrategy::DEFAULT_GROUP, 'lug.' . $name], $context->getGroups()); $this->assertSame($null, $context->getSerializeNull()); }