I got this error when running a test batch with more than one test case:

[Fri Jan 22 10:01:06 2010] [error] [client 127.0.0.1] PHP Fatal error:  require_once(): Failed opening required '' (include_path='.:/usr/lib/php5/20060613+lfs:/var/www/brgm/test/www:/var/www/test/www/include') in /var/www/test/www/sites/all/modules/devel/simpletest/simpletest.module on line 211, referer: http://test.guinevere/batch?op=start&id=90
[Fri Jan 22 10:01:06 2010] [error] [client 127.0.0.1] PHP Stack trace:, referer: http://test.guinevere/batch?op=start&id=90
[Fri Jan 22 10:01:06 2010] [error] [client 127.0.0.1] PHP   1. {main}() /var/www/test/www/index.php:0, referer: http://test.guinevere/batch?op=start&id=90
[Fri Jan 22 10:01:06 2010] [error] [client 127.0.0.1] PHP   2. menu_execute_active_handler() /var/www/test/www/index.php:18, referer: http://test.guinevere/batch?op=start&id=90
[Fri Jan 22 10:01:06 2010] [error] [client 127.0.0.1] PHP   3. call_user_func_array() /var/www/test/www/includes/menu.inc:348, referer: http://test.guinevere/batch?op=start&id=90
[Fri Jan 22 10:01:06 2010] [error] [client 127.0.0.1] PHP   4. system_batch_page() /var/www/test/www/includes/menu.inc:0, referer: http://test.guinevere/batch?op=start&id=90
[Fri Jan 22 10:01:06 2010] [error] [client 127.0.0.1] PHP   5. _batch_page() /var/www/test/www/modules/system/system.admin.inc:1809, referer: http://test.guinevere/batch?op=start&id=90
[Fri Jan 22 10:01:06 2010] [error] [client 127.0.0.1] PHP   6. _batch_do() /var/www/test/www/includes/batch.inc:34, referer: http://test.guinevere/batch?op=start&id=90
[Fri Jan 22 10:01:06 2010] [error] [client 127.0.0.1] PHP   7. _batch_process() /var/www/test/www/includes/batch.inc:106, referer: http://test.guinevere/batch?op=start&id=90
[Fri Jan 22 10:01:06 2010] [error] [client 127.0.0.1] PHP   8. call_user_func_array() /var/www/test/www/includes/batch.inc:189, referer: http://test.guinevere/batch?op=start&id=90
[Fri Jan 22 10:01:06 2010] [error] [client 127.0.0.1] PHP   9. _simpletest_batch_operation() /var/www/test/www/includes/batch.inc:0, referer: http://test.guinevere/batch?op=start&id=90

Is it a real bug or did I miswrote my tests?
What's disturbing here is when I run a batch with only one test case, it works fine.

PHP reports that the error comes from this particular three lines of code:

/**
 * Batch operation callback.
 */
function _simpletest_batch_operation($test_list_init, $test_id, &$context) {
  ..

  // Drupal 6.
  require_once drupal_get_path('module', 'simpletest') . '/drupal_web_test_case.php';
  $classes = simpletest_test_get_all_classes();
  require_once $classes[$test_class]['file'];

 ..
}

It might be a backport side effet ?

Comments

boombatower’s picture

Version: 6.x-2.10 » 6.x-2.x-dev
Assigned: Unassigned » boombatower
Status: Active » Postponed (maintainer needs more info)

Have you cleared your cache and please try this on the latest dev.

pounard’s picture

Cache has been cleared about a thousand times, Drupal and SimpleTest cache.
CCK and SimpleTest test cases work as expected.

Note: I use only DrupalUnitTestCase as parent class (I'm writing API tests, not functionnal tests). The bug seems to happen only when there is more than one DrupalUnitTestCase test case in the batch (I have one DrupalWebTestCase, and I can include it with a single other DrupalUnitTestCase, whatever is I tried them all, it works).

I'll try the -dev version in the next hours.

pounard’s picture

Hi! Sorry I took my time (a lot of work).

I finally tested with latest -dev version (dated January 27th), and I get more or less the same error:

[Mon Feb 01 11:56:53 2010] [error] [client 127.0.0.1] PHP Fatal error:  require_once(): Failed opening required '' (include_path='.:/usr/lib/php5/20060613+lfs:/var/www/brgm/test/www:/var/www/brgm/test/www/include') in /var/www/brgm/test/www/sites/all/modules/devel/simpletest/simpletest.module on line 211, referer: http://test.brgm.guinevere/batch?op=start&id=104
[Mon Feb 01 11:56:53 2010] [error] [client 127.0.0.1] PHP Stack trace:, referer: http://test.brgm.guinevere/batch?op=start&id=104
[Mon Feb 01 11:56:53 2010] [error] [client 127.0.0.1] PHP   1. {main}() /var/www/brgm/test/www/index.php:0, referer: http://test.brgm.guinevere/batch?op=start&id=104
[Mon Feb 01 11:56:53 2010] [error] [client 127.0.0.1] PHP   2. menu_execute_active_handler() /var/www/brgm/test/www/index.php:18, referer: http://test.brgm.guinevere/batch?op=start&id=104
[Mon Feb 01 11:56:53 2010] [error] [client 127.0.0.1] PHP   3. call_user_func_array() /var/www/brgm/test/www/includes/menu.inc:348, referer: http://test.brgm.guinevere/batch?op=start&id=104
[Mon Feb 01 11:56:53 2010] [error] [client 127.0.0.1] PHP   4. system_batch_page() /var/www/brgm/test/www/includes/menu.inc:0, referer: http://test.brgm.guinevere/batch?op=start&id=104
[Mon Feb 01 11:56:53 2010] [error] [client 127.0.0.1] PHP   5. _batch_page() /var/www/brgm/test/www/modules/system/system.admin.inc:1809, referer: http://test.brgm.guinevere/batch?op=start&id=104
[Mon Feb 01 11:56:53 2010] [error] [client 127.0.0.1] PHP   6. _batch_do() /var/www/brgm/test/www/includes/batch.inc:34, referer: http://test.brgm.guinevere/batch?op=start&id=104
[Mon Feb 01 11:56:53 2010] [error] [client 127.0.0.1] PHP   7. _batch_process() /var/www/brgm/test/www/includes/batch.inc:106, referer: http://test.brgm.guinevere/batch?op=start&id=104
[Mon Feb 01 11:56:53 2010] [error] [client 127.0.0.1] PHP   8. call_user_func_array() /var/www/brgm/test/www/includes/batch.inc:189, referer: http://test.brgm.guinevere/batch?op=start&id=104
[Mon Feb 01 11:56:53 2010] [error] [client 127.0.0.1] PHP   9. _simpletest_batch_operation() /var/www/brgm/test/www/includes/batch.inc:0, referer: http://test.brgm.guinevere/batch?op=start&id=104

And I confirm that when I run a batch with many DrupalWebTestCase test suites, it works, when I run a batch with one or more DrupalWebTestCase and only one DrupalUnitTestCase, it works, and when there is two or more DrupalUnitTestCase, it always fail.

EDIT: I'd like to try with another module's implementation which contains more than one DrupalUnitTestCase, but it seems that unit tests are not widely used. If you known such module, I'll test with it to be sure this problem is not due to my environment.

pounard’s picture

Still nobody alive here? Sorry to bother in the issue queue, but if you need more information, I can do a lot of stuff, just tell me what you need. This issue is quite annoying for me since I'm currently working on pretty big modules and I need to heavy test them :)

boombatower’s picture

Just need to find time to figure this out myself, unless you want to debug it.

pounard’s picture

I might get to this point, I'll tell you if I do so.

pounard’s picture

I tested with other module's test (feeds module tests actually) and I experienced the same error. A feeds maintainer tested its side and said it worked. The main difference between both environments is I use PHP 5.3.

alex_b’s picture

pounard’s picture

@alex_b
Hum at first look I'd say no, but I might be wrong.

@boombatower
More information about what is happening, the reason why it fails is here (I'm cc-ing code on which I'll add comments).

simpletest.module, line 209

  require_once drupal_get_path('module', 'simpletest') . '/drupal_web_test_case.php';
  /*
   * Added comments. 
   * I started debugging here (I dumped some vars in files). The $classes
   * array here is empty.
   */
  $classes = simpletest_test_get_all_classes();
  require_once $classes[$test_class]['file'];

simpletest.module, line 401

function simpletest_test_get_all_classes() {
  // Must load DrupalWebTestCase before loading any other test classes which
  // will extend it.
  require_once 'drupal_web_test_case.php';

  $classes = array();
  /*
   * Added comment.
   * After doing debuging, this call is OK, all modules where found.
   */
  $files = module_rebuild_cache();
  foreach ($files as $file) {
    $directory = dirname($file->filename);
    $test_files = file_scan_directory($directory, '\.test$', array('.', '..', 'CVS'), FALSE, FALSE);
    $test_files += file_scan_directory($directory . '/tests', '\.test$');

    /*
     * Added comment.
     * Did a bit more, file_scan_directory finds all the test classes, so all
     * OK until the code reaches here.
     */
    foreach ($test_files as $test_file) {
      /*
       * Added comment.
       * I think the bug is right here, do really known why, but it seems that
       * the get_declared_classes() function does not behave like it should.
       */
      $pre = get_declared_classes();
      require_once $test_file->filename;
      $post = get_declared_classes();

      /*
       * Added comment.
       * I did some brutal variable dump to files to check the diff was OK.
       * What is happening on my environment is this diff is not OK. Here on my
       * box, $classes_new is an empty array.
       * 
       * IMHO, there is two possible errors here:
       *   - It can be an array_diff() or a get_declared_classes() functions
       *     behavior change with PHP 5.3 (but I don't think so).
       *   - Else it can that test files have already been included sooner at
       *     Drupal/batch bootstrap or at SimpleTest module bootstrap.
       * I read the PHP documentation about these two functions, and no notices
       * have been written about PHP 5.3, so I think this is the second
       * assumption the correct one. 
       */
      $classes_new = array_values(array_diff($post, $pre));
      foreach ($classes_new as $class) {
        $classes[$class] = array('file' => $test_file->filename, 'class' => $class);
      }
    }
  }

  return $classes;
}

Hope it can help.

pounard’s picture

@boombatower
I'm sure now, after some variable dumps, that $pre and $post are the same when running my batch (but it remains weird, it happens only when I have 2 or more DrupalUnitTestCase in the same group).

pounard’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

A lot of time passed since, and I changed of linux distro, Drupal core version, modules version, still using SimpleTests and I can't reproduce this bug, I think it was environment related (may be APC or something like this), unable to reproduce it, I close this issue.

mdorrell’s picture

Status: Closed (fixed) » Needs review
StatusFileSize
new499 bytes

I have experienced the same issue, this shouldn't be closed. It seems to be because the module tries to require_once on an empty file. I have attached a patch that will fix this issue.

pounard’s picture

I think when trying to find out the bug cause on my environment I indeed though this part of the code was the source, but I wasn't really sure. The fact is I never got the bug again since so I can't really confirm.

mdorrell’s picture

Thanks for responding so quickly. When I was stepping through the code, it didn't really make sense that it was returning the empty file, but its probably worth checking for that before the require_once call. Maybe you could add that into the next version.

pounard’s picture

Ask this to the module maintainers :)

BrotherWolf’s picture

Hiya,

Just came across the same problem.
Tests are DrupalUnitTestCase with two Tests in same group.
Platform is Windows 7/PHP 5.29 on ZendServer.

Can confirm that this patch gets round this issue with SimpleTest.
Hats off to mdorrell for debugging and fixing, and agree that this shouldn't be closed.

mdorrell’s picture

@pounard Sorry, I just assumed you were the maintainer since you seemed to know so much about this.

@BrotherWolf Thanks, I this has been working for us on our system for a while now, so it seems safe.

I am kind of new to giving back to the community, so I don't really know if I have submitted this patch correctly. Can anyone out there help me get this pushed through to the next version?

boombatower’s picture

Status: Needs review » Fixed
StatusFileSize
new659 bytes

Your patch didn't apply cleaning...not sure if it was out of date or whatever. I updated it and committed.

Status: Fixed » Closed (fixed)

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