RouterDataCollector example

use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\RouterDataCollector;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\KernelInterface;

class RouterDataCollectorTest extends TestCase
{
    public function testRouteRedirectResponse()
    {
        $collector = new RouterDataCollector();

        $request = Request::create('http://test.com/foo?bar=baz');
        $response = new RedirectResponse('http://test.com/redirect');

        $event = $this->createControllerEvent($request);

        $collector->onKernelController($event);
        $collector->collect($request$response);

        $this->assertTrue($collector->getRedirect());
        $this->assertEquals('http://test.com/redirect', $collector->getTargetUrl());
        
Home | Imprint | This part of the site doesn't use cookies.