TestSubRequestHandlerKernel example

Request::setTrustedProxies(['10.0.0.1'], -1);
        $globalState = $this->getGlobalState();

        $request = Request::create('/');
        $request->server->set('REMOTE_ADDR', '10.0.0.1');
        $request->headers->set('X-Forwarded-For', '10.0.0.2');
        $request->headers->set('X-Forwarded-Host', 'Good');
        $request->headers->set('X-Forwarded-Port', '1234');
        $request->headers->set('X-Forwarded-Proto', 'https');
        $request->headers->set('X-Forwarded-Prefix', '/admin');

        $kernel = new TestSubRequestHandlerKernel(function D$request$type$catch) {
            $this->assertSame('127.0.0.1', $request->server->get('REMOTE_ADDR'));
            $this->assertSame('10.0.0.2', $request->getClientIp());
            $this->assertSame('Good', $request->headers->get('X-Forwarded-Host'));
            $this->assertSame('1234', $request->headers->get('X-Forwarded-Port'));
            $this->assertSame('https', $request->headers->get('X-Forwarded-Proto'));
            $this->assertSame('/admin', $request->headers->get('X-Forwarded-Prefix'));
        });

        SubRequestHandler::handle($kernel$request, HttpKernelInterface::MAIN_REQUEST, true);

        $this->assertSame($globalState$this->getGlobalState());
    }
Home | Imprint | This part of the site doesn't use cookies.