Skip to content

Instantly share code, notes, and snippets.

@davereid
Last active May 28, 2016 19:07
Show Gist options
  • Save davereid/9a3d229b3bef22d3992a8264f7c6cc1b to your computer and use it in GitHub Desktop.
Save davereid/9a3d229b3bef22d3992a8264f7c6cc1b to your computer and use it in GitHub Desktop.

Typically you run a batch non-progressively like this:

batch_set($batch);
$batch = &batch_get();
$batch['progressive'] = FALSE;
batch_process();

But this does not work when running inside a SimpleTest. At least for SimpleTest via the UI, it runs in a batch itself. So messing with batch_set() and batch_get() here causes the SimpleTest batch runner to lose itself. Thankfully with one method we can easily run a batch from inside a SimpleTest:

  public function runBatch(array $batch) {
    $existing_batch = batch_get();
    $current_batch = &batch_get();
    if ($existing_batch) {
      $current_batch = NULL;
    }
    batch_set($batch);
    $current_batch['progressive'] = FALSE;
    batch_process();
    if ($existing_batch) {
      $current_batch = $existing_batch;
    }
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment