Test Failed
Push — master ( abf703...9671b2 )
by Jonathan
04:24 queued 01:11
created

ActionScheduler_CronSchedule_Test   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 31.58 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 12
loc 38
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * Class ActionScheduler_CronSchedule_Test
5
 * @group schedules
6
 */
7
class ActionScheduler_CronSchedule_Test extends ActionScheduler_UnitTestCase {
8
	public function test_creation() {
9
		$time = as_get_datetime_object('tomorrow');
10
		$cron = CronExpression::factory('@daily');
11
		$schedule = new ActionScheduler_CronSchedule(as_get_datetime_object(), $cron);
12
		$this->assertEquals( $time, $schedule->next() );
13
	}
14
15
	public function test_next() {
16
		$time = as_get_datetime_object('2013-06-14');
17
		$cron = CronExpression::factory('@daily');
18
		$schedule = new ActionScheduler_CronSchedule($time, $cron);
19
		$this->assertEquals( as_get_datetime_object('tomorrow'), $schedule->next( as_get_datetime_object() ) );
20
	}
21
22
	public function test_is_recurring() {
23
		$schedule = new ActionScheduler_CronSchedule(as_get_datetime_object('2013-06-14'), CronExpression::factory('@daily'));
24
		$this->assertTrue( $schedule->is_recurring() );
25
	}
26
27
	public function test_cron_format() {
28
		$time = as_get_datetime_object('2014-01-01');
29
		$cron = CronExpression::factory('0 0 10 10 *');
30
		$schedule = new ActionScheduler_CronSchedule($time, $cron);
31
		$this->assertEquals( as_get_datetime_object('2014-10-10'), $schedule->next() );
32
33
		$cron = CronExpression::factory('0 0 L 1/2 *');
34
		$schedule = new ActionScheduler_CronSchedule($time, $cron);
35
		$this->assertEquals( as_get_datetime_object('2014-01-31'), $schedule->next() );
36
		$this->assertEquals( as_get_datetime_object('2014-07-31'), $schedule->next( as_get_datetime_object('2014-06-01') ) );
37
		$this->assertEquals( as_get_datetime_object('2028-11-30'), $schedule->next( as_get_datetime_object('2028-11-01') ) );
38
39
		$cron = CronExpression::factory('30 14 * * MON#3 *');
40
		$schedule = new ActionScheduler_CronSchedule($time, $cron);
41
		$this->assertEquals( as_get_datetime_object('2014-01-20 14:30:00'), $schedule->next() );
42
		$this->assertEquals( as_get_datetime_object('2014-05-19 14:30:00'), $schedule->next( as_get_datetime_object('2014-05-01') ) );
43
	}
44
}
45