Search code examples
phpsymfonyfunctional-testing

Symfony2 functional testing of Access Denied


I want to build a functional test in Symfony2 to check that guests are redirected to login, some user types are allowed on page and other are shown Access Denied.

First two I did with zero problems but whenever I try to access that page in Access Denied scenario my terminal gets flooded with content of that page (which is whole bunch of traces and debugs).

Any suggestions?


Solution

  • Create a separate environment for running tests, and setup debugging to false.

    I am not sure how you are running your tests, but if they are going through the front controller (app_dev.php), do the following:

    Copy app_dev.php to app_test.php

    Change

    $kernel = new AppKernel('dev', true);
    

    to

    $kernel = new AppKernel('test', false);
    

    The second parameter is a $debug flag.

    You can also comment out:

    //Debug::enable();
    

    EDIT:

    From the documentation, to override the debug parameter for functional tests you have to use:

    $client = static::createClient(array(
        'environment' => 'my_test_env',
        'debug'       => false,
    ));