Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPCS: tests/phpunit/migration/Runner_Test.php #1194

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions tests/phpunit/migration/Runner_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Runner_Test extends ActionScheduler_UnitTestCase {
public function setUp() {
parent::setUp();
if ( ! taxonomy_exists( PostStore::GROUP_TAXONOMY ) ) {
// register the post type and taxonomy necessary for the store to work
// register the post type and taxonomy necessary for the store to work.
$store = new PostStore();
$store->init();
}
Expand All @@ -34,57 +34,60 @@ public function test_migrate_batches() {

$runner = new Runner( $config );

$due = [];
$future = [];
$complete = [];
$due = array();
$future = array();
$complete = array();

for ( $i = 0; $i < 5; $i ++ ) {
$time = as_get_datetime_object( $i + 1 . ' minutes' );
$schedule = new ActionScheduler_SimpleSchedule( $time );
$action = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, [], $schedule );
$action = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
$future[] = $source_store->save_action( $action );

$time = as_get_datetime_object( $i + 1 . ' minutes ago' );
$schedule = new ActionScheduler_SimpleSchedule( $time );
$action = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, [], $schedule );
$action = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
$due[] = $source_store->save_action( $action );

$time = as_get_datetime_object( $i + 1 . ' minutes ago' );
$schedule = new ActionScheduler_SimpleSchedule( $time );
$action = new ActionScheduler_FinishedAction( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, [], $schedule );
$action = new ActionScheduler_FinishedAction( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, array(), $schedule );
$complete[] = $source_store->save_action( $action );
}

$created = $source_store->query_actions( [ 'per_page' => 0 ] );
$created = $source_store->query_actions( array( 'per_page' => 0 ) );
$this->assertCount( 15, $created );

$runner->run( 10 );

// due actions should migrate in the first batch
$migrated = $destination_store->query_actions( [ 'per_page' => 0, 'hook' => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK ] );
$args = array(
'per_page' => 0,
'hook' => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK,
);
Comment on lines +63 to +66
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, shortens things up a little.


// due actions should migrate in the first batch.
$migrated = $destination_store->query_actions( $args );
$this->assertCount( 5, $migrated );

$remaining = $source_store->query_actions( [ 'per_page' => 0, 'hook' => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK ] );
$remaining = $source_store->query_actions( $args );
$this->assertCount( 10, $remaining );


$runner->run( 10 );

// pending actions should migrate in the second batch
$migrated = $destination_store->query_actions( [ 'per_page' => 0, 'hook' => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK ] );
// pending actions should migrate in the second batch.
$migrated = $destination_store->query_actions( $args );
$this->assertCount( 10, $migrated );

$remaining = $source_store->query_actions( [ 'per_page' => 0, 'hook' => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK ] );
$remaining = $source_store->query_actions( $args );
$this->assertCount( 5, $remaining );


$runner->run( 10 );

// completed actions should migrate in the third batch
$migrated = $destination_store->query_actions( [ 'per_page' => 0, 'hook' => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK ] );
// completed actions should migrate in the third batch.
$migrated = $destination_store->query_actions( $args );
$this->assertCount( 15, $migrated );

$remaining = $source_store->query_actions( [ 'per_page' => 0, 'hook' => ActionScheduler_Callbacks::HOOK_WITH_CALLBACK ] );
$remaining = $source_store->query_actions( $args );
$this->assertCount( 0, $remaining );

}
Expand Down
Loading