What is the new pattern for writing ORM unit tests with symfony 1.1?

I began by following the book's instructions regarding autoloading ORM
classes for unit tests:
http://www.symfony-project.org/book/1_0/15-Unit-and-Functional-Testing#Stubs,%20Fixtures,%20and%20Autoloading

However it and the corresponding chapter in trunk (symfony/doc/15-Unit-
and-Functional-Testing.txt r61117) are out of date:
sfAutoload::initSimpleAutoload() no longer exists.

I eventually stumbled on the example in symfony/test/bootstrap/
unit.php and following it, added to my ORM unit tests:

<?php

require_once(dirname(__FILE__).'/../bootstrap/unit.php');

require_once($sf_symfony_lib_dir.'/util/sfSimpleAutoload.class.php');
require_once($sf_symfony_lib_dir.'/util/sfToolkit.class.php');
$autoload = sfSimpleAutoload::getInstance(sfToolkit::getTmpDir().'/
sf_autoload_unit_'.md5(__FILE__).'.data');
$autoload->addDirectory($sf_symfony_lib_dir);
$autoload->addDirectory(SF_ROOT_DIR.'/lib/model');
$autoload->register();

set_include_path(get_include_path().PATH_SEPARATOR.
$sf_symfony_lib_dir.'/plugins/sfPropelPlugin/lib/vendor');
[...]

Is this the new pattern for writing ORM unit tests with symfony 1.1?

For some tests, I additionally need to load fixtures. Again, I began
by following the book's instructions:
http://www.symfony-project.org/book/1_0/15-Unit-and-Functional-Testing#Stubs,%20Fixtures,%20and%20Autoloading

However I kept getting the error:

Fatal error: Uncaught exception 'PropelException' with message 'No
connection params set for propel' in /home/jablko/public_html/qubit/
lib/vendor/symfony/lib/plugins/sfPropelPlugin/lib/vendor/propel/
Propel.php:476

To get around this, I eventually used A) the lines from my ORM unit
test pattern, B) more lines from symfony/test/bootstrap/unit.php, C)
instructions from the book, and D) hacks:

<?php

A) require_once(dirname(__FILE__).'/../bootstrap/unit.php');

B) require_once($sf_symfony_lib_dir.'/config/sfConfig.class.php');
B) sfConfig::set('sf_symfony_lib_dir', $sf_symfony_lib_dir);
B) sfConfig::set('sf_symfony_data_dir', $sf_symfony_data_dir);

A) require_once($sf_symfony_lib_dir.'/util/
sfSimpleAutoload.class.php');
A) require_once($sf_symfony_lib_dir.'/util/sfToolkit.class.php');
A) $autoload = sfSimpleAutoload::getInstance(sfToolkit::getTmpDir().'/
sf_autoload_unit_'.md5(__FILE__).'.data');
A) $autoload->addDirectory($sf_symfony_lib_dir);
A) $autoload->addDirectory(SF_ROOT_DIR.'/lib/model');
A) $autoload->register();

A) set_include_path(get_include_path().PATH_SEPARATOR.
$sf_symfony_lib_dir.'/plugins/sfPropelPlugin/lib/vendor');

D) sfConfig::set('sf_root_dir', SF_ROOT_DIR);
D) sfConfig::set('sf_app_config_dir_name', 'config');

D) sfConfig::set('sf_app_module_dir', sfToolkit::getTmpDir());
D) sfConfig::set('sf_config_cache_dir', sfToolkit::getTmpDir());

C) $databaseManager = new sfDatabaseManager;

D) require_once($sf_symfony_data_dir.'/skeleton/app/app/lib/
myUser.class.php');
D) require_once($sf_symfony_lib_dir.'/plugins/sfPropelPlugin/lib/
propel/sfPropelAutoload.php');

C) $data = new sfPropelData;
C) $data->loadData(SF_ROOT_DIR.'/data/fixtures/greekTree.yml');
[...]

In the end it worked, but I encountered several problems along the
way:

1) sfAutoload is configured by symfony/lib/plugins/sfPropelPlugin/
config/autoload.yml to load sfPropelAutoload.php for the "Propel"
class:

  propel_class:
    name:           propel class
    files:
      Propel:       %SF_SYMFONY_LIB_DIR%/plugins/sfPropelPlugin/lib/
propel/sfPropelAutoload.php

sfPropelAutoload.php in turn loads Propel.php and calls:

Propel::setConfiguration(sfPropelDatabase::getConfiguration());

This is a bit complex and doesn't work with sfSimpleAutoloader. It
doesn't work because sfPropelAutoload.php doesn't contain a "Propel"
class: sfSimpleAutoloader loads Propel.php directly. Consequently
Propel::setConfiguration() is never called, resulting in my
PropelException: No connection params set for propel

I hack around this by manually loading sfPropelAutoloader.php:

require_once($sf_symfony_lib_dir.'/plugins/sfPropelPlugin/lib/propel/
sfPropelAutoload.php');

Is there a reason symfony doesn't use a wrapper function,
sfPropelDatabase::getConnection(), instead of the sfAutoloader, to
call Propel::setConfiguration() before Propel::getConnection()?

2) I was getting class name conflicts because sfSimpleAutoloader found
class sfRequest in symfony/lib/plugins/sfCompat10Plugin/test/unit/
validator/sfCompareValidatorTest.php and loaded that file instead of
sfRequest.class.php

I hack around this by deleting the symfony/lib/plugins/
sfCompat10Plugin/test and symfony/lib/plugins/sfPropelPlugin/test
directories.

Is there a reason bundled plugins are organized in the
sf_symfony_lib_dir/plugins directory, instead of symfony/plugins,
analogous to the organization of the project directory?

3) The symfony factories.yml references the class myUser, which is
ordinarily in an app's sf_app_lib_dir, so in unit tests I manually
load:

require_once($sf_symfony_data_dir.'/skeleton/app/app/lib/
myUser.class.php');

What is the new pattern for loading fixtures in symfony 1.1?

Much thanks for all your work developing the symfony framework! Jack
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony developers" 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-devs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to