Search code examples
phpsymfony1symfony-1.4functional-testing

How to overwrite sfConfig setting in functional lime test in symfony 1.4


My Problem is the following i wanted to test some functionality that depended on a certain setting in the sfConfig. Proposed the setting is app_foo and its default is false.

The "standard" way to test is like:

$browser = new sfTestFunctional(new sfBrowser());

$browser->
  get('/path_to/index')->
  ...
  end();

BUT it does not work to change the setting like

sfConfig::set('app_foo', true);
$browser = new sfTestFunctional(new sfBrowser());

Solution

  • The sfConfig cannot be overwritten in the test because the sfConfig is reset on the next request.

    BUT a field named 'rawConfiguration' in the browser instance is added to the sfConfig for the request. So the solution is to set this array:

    $browserEngine = new sfBrowser();
    $browser = new sfTestFunctional($browserEngine);
    // overwrite an sfConfig parameter in the browser context
    $browserEngine->rawConfiguration = array_merge($browserEngine->rawConfiguration, array('app_foo' => true));
    

    Then the action knows the sfConfig::get('app_foo') with the value true.