Simon Cast
Simon Cast

Reputation: 255

Symfony 1.4 not loading sfTestFunctional failing with class not found

I've done my functional tests and now I want to run them. However, every time I run them I get sfTestFunctional class not found.

As far as I can tell the functional.php bootstrap is not autoloading the classes from the framework. Any reason why this could be?

This is my functional bootstrap

// guess current application
if (!isset($app))
{
  $traces = debug_backtrace();
  $caller = $traces[0];

  $dirPieces = explode(DIRECTORY_SEPARATOR, dirname($caller['file']));
  $app = array_pop($dirPieces);
}

require_once dirname(__FILE__).'/../../config/ProjectConfiguration.class.php';
$configuration = ProjectConfiguration::getApplicationConfiguration($app, 'test', isset($debug) ? $debug : true);

sfContext::createInstance($configuration);


// remove all cache
sfToolkit::clearDirectory(sfConfig::get('sf_app_cache_dir'));

$doctrine = new sfDoctrineDropDbTask($configuration->getEventDispatcher(), new sfAnsiColorFormatter());
$doctrine->run(array(), array("--no-confirmation","--env=test"));

$doctrine = new sfDoctrineBuildDbTask($configuration->getEventDispatcher(), new sfAnsiColorFormatter());
$doctrine->run(array(), array("--env=test"));

$doctrine = new sfDoctrineInsertSqlTask($configuration->getEventDispatcher(), new sfAnsiColorFormatter());
$doctrine->run(array(), array("--env=test"));

This is what is in my the functional tests

include(dirname(__FILE__).'/../../bootstrap/functional.php');

$browser = sfTestFunctional(new sfBrowser());
Doctrine_Core::loadData(sfConfig::get('sf_test_dir').'/fixtures/fixtures_initial.yml');

Upvotes: 0

Views: 820

Answers (2)

Simon Cast
Simon Cast

Reputation: 255

Ok. So after banging my head against the wall, I found a solution.

For some reason within the test environment custom filters are not autoloaded. The solution is to add require_once for all the custom filters to the ProjectConfiguration file. Here is the example of what I did:

if(sfConfig::get('sf_environment') == 'test' && sfConfig::get('sf_app') == 'frontend')
{
    require_once sfConfig::get('sf_app_lib_dir').'/myFilter.class.php';
    require_once sfConfig::get('sf_app_lib_dir').'/myotherFilter.class.php';
    require_once sfConfig::get('sf_app_lib_dir').'/lovefiltersFilter.php';
    require_once sfConfig::get('sf_app_lib_dir').'/eventsManagement.class.php';

    require_once sfConfig::get('sf_test_dir').'/ProdPadTestFunctional.class.php';
}

I also had to add my custom testFuntional class as well. This might be more elegantly done using the autoload.yml file.

Upvotes: 1

j0k
j0k

Reputation: 22756

I spot the problem:

$browser = sfTestFunctional(new sfBrowser());

You should write:

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

Upvotes: 0

Related Questions