Skip to content

Commit

Permalink
Make the migration job name explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
m1r0 committed Sep 4, 2023
1 parent bef4b79 commit e7332eb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
8 changes: 6 additions & 2 deletions includes/class-sensei.php
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,12 @@ public function initialize_global_objects() {
// Student progress migration.
if ( $use_tables ) {
$this->migration_scheduler = new Migration_Job_Scheduler( $this->action_scheduler );
$this->migration_scheduler->register_job( new Migration_Job( new Student_Progress_Migration() ) );
$this->migration_scheduler->register_job( new Migration_Job( new Quiz_Migration() ) );
$this->migration_scheduler->register_job(
new Migration_Job( 'student_progress_migration', new Student_Progress_Migration() )
);
$this->migration_scheduler->register_job(
new Migration_Job( 'quiz_migration', new Quiz_Migration() )
);
( new Migration_Tool( \Sensei_Tools::instance(), $this->migration_scheduler ) )->init();
}

Expand Down
24 changes: 10 additions & 14 deletions includes/internal/migration/class-migration-job.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

namespace Sensei\Internal\Migration;

use ReflectionClass;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}
Expand All @@ -21,6 +19,12 @@
* @since $$next-version$$
*/
class Migration_Job {
/**
* Job name.
*
* @var string
*/
private $name;

/**
* Migration.
Expand All @@ -36,23 +40,15 @@ class Migration_Job {
*/
private $is_complete = false;

/**
* Job name.
*
* @var string
*/
private $name;

/**
* Migration_Job constructor.
*
* @param string $name The job name. Should be hook friendly (lowercase, underscored).
* @param Migration_Abstract $migration Migration.
*/
public function __construct( Migration_Abstract $migration ) {
public function __construct( string $name, Migration_Abstract $migration ) {
$this->name = $name;
$this->migration = $migration;
$this->name = strtolower(
( new ReflectionClass( $migration ) )->getShortName()
);
}

/**
Expand Down Expand Up @@ -94,7 +90,7 @@ public function is_complete(): bool {
}

/**
* Get job name.
* Get the job name.
*
* @internal
*
Expand Down
10 changes: 5 additions & 5 deletions tests/unit-tests/internal/migration/test-class-migration-job.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Migration_Job_Test extends \WP_UnitTestCase {
public function testRun_Always_RunsMigration() {
/* Arrange. */
$migration = $this->createMock( Student_Progress_Migration::class );
$job = new Migration_Job( $migration );
$job = new Migration_Job( 'student_progress_migration', $migration );

/* Expect & Act. */
$migration
Expand All @@ -30,7 +30,7 @@ public function testIsComplete_MigrationRanWithoutInsertions_ReturnsTrue() {
$migration = $this->createMock( Student_Progress_Migration::class );
$migration->method( 'run' )->willReturn( 0 );

$job = new Migration_Job( $migration );
$job = new Migration_Job( 'student_progress_migration', $migration );
$job->run();

/* Act. */
Expand All @@ -45,7 +45,7 @@ public function testIsComplete_MigrationRanWithInsertions_ReturnsFalse() {
$migration = $this->createMock( Student_Progress_Migration::class );
$migration->method( 'run' )->willReturn( 1 );

$job = new Migration_Job( $migration );
$job = new Migration_Job( 'student_progress_migration', $migration );
$job->run();

/* Act. */
Expand All @@ -65,7 +65,7 @@ public function testGetErrors_Always_ReturnsMigrationErrors( $errors ) {
$migration = $this->createMock( Student_Progress_Migration::class );
$migration->method( 'get_errors' )->willReturn( $errors );

$job = new Migration_Job( $migration );
$job = new Migration_Job( 'student_progress_migration', $migration );

/* Act. */
$actual = $job->get_errors();
Expand All @@ -88,7 +88,7 @@ public function providerGetErrors_Always_ReturnsMigrationErrors(): array {
public function testGetName_Always_ReturnsMatchingValue() {
/* Arrange. */
$migration = new Student_Progress_Migration();
$job = new Migration_Job( $migration );
$job = new Migration_Job( 'student_progress_migration', $migration );

/* Act. */
$actual = $job->get_name();
Expand Down

0 comments on commit e7332eb

Please sign in to comment.