I'm having a problem with my classes getting included when running in simpletest...

  function setUp() {
    parent::setUp('autoload', 'dbtng', 'migrate', 'content', 'migrate_example');
    ...
  }

  function testUserImport() {
    $lookup = autoload_get_lookup(TRUE);
    $this->error(print_r($lookup, TRUE));  // BeerUserMigration is here...
    $migration = Migration::getInstance('BeerUserMigration'); // ...but can't be found here
    ...

The problem is the static $lookup in autoload_class() - when modules are being dynamically enabled, the first one to invoke an autoloaded class causes $lookup to be populated with all the classes in the the modules enabled up through that. If any later-enabled modules have classes to offer - tough luck. In this case, migrate is the first module to reference any undefined classes, so it and dbtng get their classes registered, but migrate_example is SOL.

I think the solution here is to move the static $lookup into autoload_get_lookup(), call it unconditionally from autoload_class(), and reset it along with the cache on $reset. The test can then call autoload_get_lookup(TRUE).

Sorry I don't have time at the moment to generate a proper patch against CVS (since my copy of autoload is already significantly modified), but this seems to do the trick:

function autoload_class($class) {
  $lookup = autoload_get_lookup();

  if (!empty($lookup[$class])) {
  ...

function autoload_get_lookup($reset = FALSE) {
  static $lookup;

  if (isset($lookup) && !$reset) {
    return $lookup;
  }

  if (!$reset && ($cache = cache_get('autoload:')) && isset($cache->data)) {

This isn't a unique problem - anything that hides data gathered from enabled modules in unresettable statics is prone to giving problems in simpletest (don't get me started on trying to test Views-related code).

Comments

Crell’s picture

Status: Active » Needs review

I hate static variables. I really do.

I've committed a change based on this issue. As soon as the new tarball is built please give it a whirl and see if it fixes the issue. If so, mark it fixed. Thanks.

mikeryan’s picture

Status: Needs review » Fixed

That did it, thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.