I'm trying to write test cases for my custom module and in order to speed things along for current and future testing I defined a garbage class that can spit out random data. However the testing module cannot seem to locate my Garbage class. After some debugging I realize that Drupal looks in the registry table to find the class and while my class is defined in the default registry table, simpletest creates it's own custom registry table to run tests which doesn't contain my class or it's location. Is there any way around this or some way to force simpletest to make an exact duplicate of the registry table?


  • The garbage class is located in a separate file (Garbage.php)
  • Yes I do have 'files[] = Garbage.php' in my .info file.
  • While I could just move the garbage functions into test case itself, I may need to reuse it for other tests later on so having it in a separate class is ideal.

Garbage class

    class Garbage {
        public static function getGarbageString(int $i = 1) {
            $return = array();
            for ($j = 0; $j < $i; $j++) {
                $return[$j] = self::_getRandomString();

            return $i == 1 ? $return[0] : $return;

        private static function _getRandomChar() {
            return chr(mt_rand(33,126));

        private static function _getRandomString() {
            $length = mt_rand(1, 255);
            $return = '';
            for ($i = 0; $i < $length; $i++) {
                $return .= self::_getRandomChar();

            return $return;

Located in .module file

    function getRecord($recordName) {
        return $records[$recordName];

Located in RecordTestCases which extends DrupalWebTestCase

    public function testGetRecord() {
        $badData = Garbage::getGarbageString();
        $this->assertNull(getRecord($badData), 'Testing get record with bad data');

1 Answer 1


If getRecord() and testGetRecord() are methods of the Garbage class, then you have a misplaced } bracket.

Alternately, testGetRecord() will have no idea what to do with $this, since it's not part of a class definition. It would need to be a method of a subclass of DrupalUnitTest, or DrupalWebTest. As-is, PHP will choke on it.

  • Sorry for not clarying, they're not in Garbage class. getRecord is in .module file and testGetRecord is in the test class.
    – Sathariel
    Commented Jun 14, 2012 at 18:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.