During SimpleTest i got htis error

PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'gemm.simpletest959632registry' doesn't exist: SELECT r.filename AS filename FROM {registry} r WHERE (r.name LIKE :db_condition_placeholder_0 ESCAPE '\\') AND (r.type = :db_condition_placeholder_1) ; Array ( [:db_condition_placeholder_0] => Drupal\\svr\\Foo\\Foo [:db_condition_placeholder_1] => trait ) in _registry_check_code() (line 3205 of /var/www/includes/bootstrap.inc).

I fixed it by using a try .. catch.

    try {
        $file = Database::getConnection('default', 'default')
            ->select('registry', 'r', array('target' => 'default'))
            ->fields('r', array('filename'))
            // Use LIKE here to make the query case-insensitive.
            ->condition('r.name', db_like($name), 'LIKE')
            ->condition('r.type', $type)
            ->execute()
            ->fetchField();
    } catch (PDOException $e) {
        $file = null;
    }

Is this a patch or is it an issue in SimpleTest?

Comments

HVSoftware created an issue. See original summary.

ennorehling’s picture

I've just met the same problem. This seems to happen when I instantiate any class in my module. My guess is that the autoloader calls drupal_autoload_trait, which tries to look for something in the Drupal registry, but because my test is a DrupalUnitTestCase, the simpletest database schema has not been created (it's only needed for DrupalWebTestCase), which causes the exception.

steinmb’s picture

Version: 7.43 » 7.x-dev

So what is best practice here. Do we have to manually include those classes with a include_once() in the setUp() method. Seems a little clunky.

pmaruszczyk’s picture

+1

ennorehling’s picture

If you extend DrupalWebTestCase, and call the parent::setUp method listing the names of modules from which your tests need to execute code, you should not have to include_once anything, given that your .info files have correct dependencies and file lists. I wish it was easier to use DrupalUnitTestCase, because setting up the modules and their database schemas takes an awfully long time, but that's not so easily solved :-(

steinmb’s picture

Category: Bug report » Support request
Status: Active » Fixed

I suggest we close this as a support req. I have my doubts that a lot of improvements to simpletest and autoloading will be done in D7. After all we are getting close to dropping D9.

Status: Fixed » Closed (fixed)

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