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/LogMigrator_Test.php #1193

Merged
merged 9 commits into from
Oct 30, 2024
40 changes: 24 additions & 16 deletions tests/phpunit/migration/LogMigrator_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@
* @group migration
*/
class LogMigrator_Test extends ActionScheduler_UnitTestCase {
function setUp() {
public function setUp() {
parent::setUp();
if ( ! taxonomy_exists( ActionScheduler_wpPostStore::GROUP_TAXONOMY ) ) {
// register the post type and taxonomy necessary for the store to work
if ( ! taxonomy_exists( ActionScheduler_wpPostStore::GROUP_TAXONOMY ) ) {
// register the post type and taxonomy necessary for the store to work.
$store = new ActionScheduler_wpPostStore();
$store->init();
}
}

public function test_migrate_from_wpComment_to_db() {
$source = new ActionScheduler_wpCommentLogger();
$destination = new ActionScheduler_DBLogger();
$migrator = new LogMigrator( $source, $destination );
$source_action_id = rand( 10, 10000 );
$destination_action_id = rand( 10, 10000 );
$source = new ActionScheduler_wpCommentLogger();
$destination = new ActionScheduler_DBLogger();
$migrator = new LogMigrator( $source, $destination );
$source_action_id = wp_rand( 10, 10000 );
$destination_action_id = wp_rand( 10, 10000 );

$logs = [];
for ( $i = 0 ; $i < 3 ; $i++ ) {
for ( $j = 0 ; $j < 5 ; $j++ ) {
$logs[ $i ][ $j ] = md5(rand());
if ( $i == 1 ) {
$logs = array();
for ( $i = 0; $i < 3; $i++ ) {
for ( $j = 0; $j < 5; $j++ ) {
$logs[ $i ][ $j ] = md5( wp_rand() );
if ( 1 === $i ) {
$source->log( $source_action_id, $logs[ $i ][ $j ] );
}
}
Expand All @@ -36,9 +36,17 @@ public function test_migrate_from_wpComment_to_db() {
$migrator->migrate( $source_action_id, $destination_action_id );

$migrated = $destination->get_logs( $destination_action_id );
$this->assertEqualSets( $logs[ 1 ], array_map( function( $log ) { return $log->get_message(); }, $migrated ) );
$this->assertEqualSets(
$logs[1],
array_map(
function( $log ) {
return $log->get_message();
},
$migrated
)
);

// no API for deleting logs, so we leave them for manual cleanup later
// no API for deleting logs, so we leave them for manual cleanup later.
$this->assertCount( 5, $source->get_logs( $source_action_id ) );
}
}
}
Loading