You are here

public function FeatureContext::cleanupQueue in Open Social 10.0.x

Same name and namespace in other branches
  1. 10.3.x tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::cleanupQueue()
  2. 10.1.x tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::cleanupQueue()
  3. 10.2.x tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::cleanupQueue()

Remove any queue items that were created.

@AfterScenario

File

tests/behat/features/bootstrap/FeatureContext.php, line 731

Class

FeatureContext
Defines application features from the specific context.

Namespace

Drupal\social\Behat

Code

public function cleanupQueue(AfterScenarioScope $scope) {
  $workerManager = \Drupal::service('plugin.manager.queue_worker');

  /** @var Drupal\Core\Queue\QueueFactory; $queue */
  $queue = \Drupal::service('queue');
  foreach ($workerManager
    ->getDefinitions() as $name => $info) {

    /** @var Drupal\Core\Queue\QueueInterface $worker */
    $worker = $queue
      ->get($name);
    if ($worker
      ->numberOfItems() > 0) {
      while ($item = $worker
        ->claimItem()) {

        // If we don't just delete them, process the item first.
        $worker
          ->deleteItem($item);
      }
    }
  }
}