ApiPlatform\Core\Tests\EventListener\DeserializeListenerTest::testContentNegotiation PHP Method

testContentNegotiation() public method

    public function testContentNegotiation()
    {
        $eventProphecy = $this->prophesize(GetResponseEvent::class);
        $request = new Request([], [], ['_api_resource_class' => 'Foo', '_api_collection_operation_name' => 'post'], [], [], [], '{}');
        $request->setMethod(Request::METHOD_POST);
        $request->headers->set('Content-Type', 'text/xml');
        $request->setFormat('xml', 'text/xml');
        // Workaround to avoid weird behaviors
        $eventProphecy->getRequest()->willReturn($request)->shouldBeCalled();
        $serializerProphecy = $this->prophesize(SerializerInterface::class);
        $serializerProphecy->deserialize('{}', 'Foo', 'xml', [])->willReturn(new \stdClass())->shouldBeCalled();
        $serializerContextBuilderProphecy = $this->prophesize(SerializerContextBuilderInterface::class);
        $serializerContextBuilderProphecy->createFromRequest(Argument::type(Request::class), false, Argument::type('array'))->willReturn([])->shouldBeCalled();
        $listener = new DeserializeListener($serializerProphecy->reveal(), $serializerContextBuilderProphecy->reveal(), ['jsonld' => ['application/ld+json'], 'xml' => ['text/xml']]);
        $listener->onKernelRequest($eventProphecy->reveal());
    }