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/schedules/ActionScheduler_CronSchedule_Test.php #1200

Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@
<exclude-pattern>lib/*</exclude-pattern>
<exclude-pattern>tests/*</exclude-pattern>
</rule>

<rule ref="Squiz.Commenting.FunctionComment.Missing">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
</ruleset>
49 changes: 24 additions & 25 deletions tests/phpunit/schedules/ActionScheduler_CronSchedule_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
*/
class ActionScheduler_CronSchedule_Test extends ActionScheduler_UnitTestCase {
public function test_creation() {
$time = as_get_datetime_object('tomorrow');
$cron = CronExpression::factory('@daily');
$time = as_get_datetime_object( 'tomorrow' );
$cron = CronExpression::factory( '@daily' );
$start = clone $time;
$start->modify( '-1 hour' );
$schedule = new ActionScheduler_CronSchedule( $start, $cron );
$this->assertEquals( $time, $schedule->get_date() );
$this->assertEquals( $start, $schedule->get_first_date() );

// Test delaying for a future start date
// Test delaying for a future start date.
$start->modify( '+1 week' );
$time->modify( '+1 week' );

Expand All @@ -24,15 +24,15 @@ public function test_creation() {
}

public function test_creation_with_first_date() {
$time = as_get_datetime_object( 'tomorrow' );
$cron = CronExpression::factory( '@daily' );
$time = as_get_datetime_object( 'tomorrow' );
$cron = CronExpression::factory( '@daily' );
$start = clone $time;
$start->modify( '-1 hour' );
$schedule = new ActionScheduler_CronSchedule( $start, $cron );
$this->assertEquals( $time, $schedule->get_date() );
$this->assertEquals( $start, $schedule->get_first_date() );

// Test delaying for a future start date
// Test delaying for a future start date.
$first = clone $time;
$first->modify( '-1 day' );
$start->modify( '+1 week' );
Expand All @@ -44,33 +44,32 @@ public function test_creation_with_first_date() {
}

public function test_next() {
$time = as_get_datetime_object('2013-06-14');
$cron = CronExpression::factory('@daily');
$schedule = new ActionScheduler_CronSchedule($time, $cron);
$this->assertEquals( as_get_datetime_object('tomorrow'), $schedule->get_next( as_get_datetime_object() ) );
$time = as_get_datetime_object( '2013-06-14' );
$cron = CronExpression::factory( '@daily' );
$schedule = new ActionScheduler_CronSchedule( $time, $cron );
$this->assertEquals( as_get_datetime_object( 'tomorrow' ), $schedule->get_next( as_get_datetime_object() ) );
}

public function test_is_recurring() {
$schedule = new ActionScheduler_CronSchedule(as_get_datetime_object('2013-06-14'), CronExpression::factory('@daily'));
$schedule = new ActionScheduler_CronSchedule( as_get_datetime_object( '2013-06-14' ), CronExpression::factory( '@daily' ) );
$this->assertTrue( $schedule->is_recurring() );
}

public function test_cron_format() {
$time = as_get_datetime_object('2014-01-01');
$cron = CronExpression::factory('0 0 10 10 *');
$schedule = new ActionScheduler_CronSchedule($time, $cron);
$this->assertEquals( as_get_datetime_object('2014-10-10'), $schedule->get_date() );
$time = as_get_datetime_object( '2014-01-01' );
$cron = CronExpression::factory( '0 0 10 10 *' );
$schedule = new ActionScheduler_CronSchedule( $time, $cron );
$this->assertEquals( as_get_datetime_object( '2014-10-10' ), $schedule->get_date() );

$cron = CronExpression::factory('0 0 L 1/2 *');
$schedule = new ActionScheduler_CronSchedule($time, $cron);
$this->assertEquals( as_get_datetime_object('2014-01-31'), $schedule->get_date() );
$this->assertEquals( as_get_datetime_object('2014-07-31'), $schedule->get_next( as_get_datetime_object('2014-06-01') ) );
$this->assertEquals( as_get_datetime_object('2028-11-30'), $schedule->get_next( as_get_datetime_object('2028-11-01') ) );
$cron = CronExpression::factory( '0 0 L 1/2 *' );
$schedule = new ActionScheduler_CronSchedule( $time, $cron );
$this->assertEquals( as_get_datetime_object( '2014-01-31' ), $schedule->get_date() );
$this->assertEquals( as_get_datetime_object( '2014-07-31' ), $schedule->get_next( as_get_datetime_object( '2014-06-01' ) ) );
$this->assertEquals( as_get_datetime_object( '2028-11-30' ), $schedule->get_next( as_get_datetime_object( '2028-11-01' ) ) );

$cron = CronExpression::factory('30 14 * * MON#3 *');
$schedule = new ActionScheduler_CronSchedule($time, $cron);
$this->assertEquals( as_get_datetime_object('2014-01-20 14:30:00'), $schedule->get_date() );
$this->assertEquals( as_get_datetime_object('2014-05-19 14:30:00'), $schedule->get_next( as_get_datetime_object('2014-05-01') ) );
$cron = CronExpression::factory( '30 14 * * MON#3 *' );
$schedule = new ActionScheduler_CronSchedule( $time, $cron );
$this->assertEquals( as_get_datetime_object( '2014-01-20 14:30:00' ), $schedule->get_date() );
$this->assertEquals( as_get_datetime_object( '2014-05-19 14:30:00' ), $schedule->get_next( as_get_datetime_object( '2014-05-01' ) ) );
}
}

Loading