2019-06-10 11:36:11 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Helper code for wc-admin unit tests.
|
|
|
|
*
|
|
|
|
* @package WooCommerce\Tests\Framework\Helpers
|
|
|
|
*/
|
|
|
|
|
2019-06-21 09:40:39 +00:00
|
|
|
namespace Automattic\WooCommerce\RestApi\UnitTests\Helpers;
|
2019-06-10 11:36:11 +00:00
|
|
|
|
|
|
|
defined( 'ABSPATH' ) || exit;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class QueueHelper.
|
|
|
|
*
|
|
|
|
* This helper class should ONLY be used for unit tests!.
|
|
|
|
*/
|
|
|
|
class QueueHelper {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all pending queued actions.
|
|
|
|
*
|
|
|
|
* @return array Pending jobs.
|
|
|
|
*/
|
|
|
|
public static function get_all_pending() {
|
|
|
|
$jobs = WC()->queue()->search(
|
|
|
|
array(
|
|
|
|
'per_page' => -1,
|
|
|
|
'status' => 'pending',
|
|
|
|
'claimed' => false,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return $jobs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run all pending queued actions.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function run_all_pending() {
|
|
|
|
$jobs = self::get_all_pending();
|
|
|
|
|
|
|
|
foreach ( $jobs as $job ) {
|
|
|
|
$job->execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run all pending queued actions.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function process_pending() {
|
|
|
|
$jobs = self::get_all_pending();
|
|
|
|
|
2019-06-10 15:32:12 +00:00
|
|
|
$queue_runner = new \ActionScheduler_QueueRunner();
|
2019-06-10 11:36:11 +00:00
|
|
|
foreach ( $jobs as $job_id => $job ) {
|
|
|
|
$queue_runner->process_action( $job_id );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|