Пример #1
0
 public function getDeserialized($className)
 {
     $request = $this->requestStack->getCurrentRequest();
     $this->prepareSerializer($request, 'Content-Type');
     $format = $this->formatParser->getSupportedFormat($request, 'Content-Type', $this->serializer);
     //make the actual deserialization
     $data = $request->getContent();
     $deserializedData = $this->serializer->deserialize($data, $className, $format);
     $this->restoreDefaultTransformers();
     return $deserializedData;
 }
Пример #2
0
 public function testSupportedFormatWithNonExistentHeader()
 {
     $headerName = "Accept";
     $headerBagMock = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\HeaderBag')->disableOriginalConstructor()->getMock();
     $headerBagMock->expects($this->atLeastOnce())->method('has')->with($this->equalTo($headerName))->willReturn(false);
     $headerBagMock->expects($this->never())->method('get');
     $requestMock = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\Request')->disableOriginalConstructor()->getMock();
     $requestMock->headers = $headerBagMock;
     $serializerMock = $this->getMockBuilder('Symfony\\Component\\Serializer\\Encoder\\EncoderInterface')->disableOriginalConstructor()->getMock();
     $serializerMock->expects($this->atLeastOnce())->method('supportsEncoding')->with($this->equalTo(FormatParser::DEFAULT_FORMAT))->willReturn(true);
     $formatParser = new FormatParser();
     $format = $formatParser->getSupportedFormat($requestMock, $headerName, $serializerMock);
     $this->assertEquals(FormatParser::DEFAULT_FORMAT, $format);
 }