I'm using functional tests in my Doctrine-based project.

One of the first steps is generally to load the fixtures data.

We've been using a loadData method like this in our functional test class:

public function loadData()
  {
    Doctrine::loadData(sfConfig::get('sf_data_dir').'/fixtures');

    return $this;
  }

It seems OK at first, but there's a problem: it doesn't know about
plugins. If you are testing functionality that expects data that gets
loaded from plugin fixture files, you're out of luck. This is a
problem because functional tests should be able to easily test the
site with its real fixtures. Although it is nice that you can take
advantage of load_data to purposely load alternate testing-only
fixtures when you actually want that.

I rummaged through sfDoctrineBaseTask and borrowed most of this from there:

  public function loadData()
  {
    $fixtures = array();
    $fixtures[] = sfConfig::get('sf_data_dir').'/fixtures';
    $configuration = sfContext::getInstance()->getConfiguration();
    $pluginPaths = $configuration->getPluginPaths();
    foreach ($pluginPaths as $pluginPath)
    {
      if (is_dir($dir = $pluginPath.'/data/fixtures'))
      {
        $fixtures[] = $dir;
      }
    }

    $append = false;
    foreach ($fixtures as $fixture)
    {
      echo("Loading file $fixture\n");
      Doctrine::loadData($fixture, $append);
      $append = true;
    }

    return $this;
  }

This seems like it ought to reproduce what the data-load task does,
but I get validation errors:

 Doctrine_Validator_Exception: Validation failed in class pkContextCMSPage

  1 field had validation error:

    * 1 validator failed on slug (unique)

Which I *don't* get if I simply call:

./symfony doctrine:data-load --env=test

Finally I wrote this version:

  public function loadData()
  {
    system(escapeshellarg(sfConfig::get('sf_root_dir') . '/symfony') .
' doctrine:data-load --env=test', $result);
    if ($result !== 0)
    {
      die("Error loading data");
    }
    return $this;
  }

That, unsurprisingly, does work. It's probably fine for Unix, it would
need work in a Windows environment (not a problem for me).

I considered "just calling" the doctrine:data-load task, but calling a
task from PHP seems to be easy only if you're calling *from* a task
and already have the "dispatcher" and "formatter" objects ready to
pass, whatever those might be.

Is my workaround the best that can be done or is there a
straightforward way to call the task?

-- 
Tom Boutell
P'unk Avenue
215 755 1330
punkave.com
window.punkave.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to