-
Notifications
You must be signed in to change notification settings - Fork 0
/
CronTest.php
129 lines (113 loc) · 4.11 KB
/
CronTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
namespace Test\Src;
use Schedule\Cron;
use InvalidArgumentException;
use PHPUnit_Framework_TestCase;
class CronTest extends PHPUnit_Framework_TestCase
{
public function testEvery()
{
$this->assertEquals('* * * * *', (new Cron())->every()->parse());
$this->assertEquals('1 * * * *', (new Cron())->every()->minutes(1)->parse());
$this->assertEquals('1 0 * * *', (new Cron())->every()->minutes(1)->hours(0)->parse());
$this->assertEquals(
'1 0 1 * *',
(new Cron())->every()->minutes(1)->hours(0)->daysOfTheMonth(1)->parse()
);
}
public function testEveryMinutes()
{
$this->assertEquals('*/1 * * * *', (new Cron())->everyMinutes(1)->parse());
$this->assertEquals(
(new Cron())->everyHours(1)->parse(),
(new Cron())->everyMinutes(60)->parse()
);
}
public function testEveryHours()
{
$this->assertEquals('0 */1 * * *', (new Cron())->everyHours(1)->parse());
$this->assertEquals(
(new Cron())->everyHours(24)->parse(),
(new Cron())->everyDays(1)->parse()
);
$this->assertEquals(
'10,20 */4 * * *',
(new Cron())->everyHours(4)->minutes(array(10, 20))->parse()
);
$this->assertEquals(
(new Cron())->everyHours(24)->parse(),
(new Cron())->everyDays(1)->parse()
);
}
public function testEveryDays()
{
$this->assertEquals('0 0 */1 * *', (new Cron())->everyDays(1)->parse());
$this->assertEquals(
'30,40,50 12,20 */1 * *',
(new Cron())->everyDays(1)->hours(array(12, 20))->minutes(array(30, 40, 50))->parse()
);
$this->assertEquals(
(new Cron())->everyDays(31)->parse(),
(new Cron())->everyMonths(1)->parse()
);
}
public function testEveryMonths()
{
$this->assertEquals('0 0 1 */1 *', (new Cron())->everyMonths(1)->parse());
$this->assertEquals(
'1 10 12,13 */1 *',
(new Cron())->everyMonths(1)->daysOfTheMonth(array(12, 13))->hours(10)->minutes(1)->parse()
);
try {
(new Cron())->everyMonths(13)->parse();
} catch (InvalidArgumentException $e) {
$this->assertEquals('Time must be lower or equal 12 months', $e->getMessage());
}
}
public function testEveryWeek()
{
$this->assertEquals('0 0 * * 0', (new Cron())->everyWeek()->parse());
$this->assertEquals(
'1 10 * 10 0',
(new Cron())->everyWeek()->months(10)->hours(10)->minutes(1)->parse()
);
}
public function testEveryWeekday()
{
$this->assertEquals('0 0 * * 1,2,3,4,5', (new Cron())->everyWeekday()->parse());
$this->assertEquals(
'1 10 * 10 1,2,3,4,5',
(new Cron())->everyWeekday()->months(10)->hours(10)->minutes(1)->parse()
);
}
public function testEveryWeekend()
{
$this->assertEquals('0 0 * * 0,6', (new Cron())->everyWeekend()->parse());
$this->assertEquals(
'1 10 * 10 0,6',
(new Cron())->everyWeekend()->months(10)->hours(10)->minutes(1)->parse()
);
}
public function testCommand()
{
$this->assertEquals(
'*/1 * * * * ENV=test HOME=/Users/tom balabalabala',
(new Cron())->everyMinutes(1)->command('balabalabala')->parse()
);
$this->assertEquals(
'*/1 * * * * ENV=test HOME=/Users/tom balabalabala >> balabalabala.log 2>&1',
(new Cron())->everyMinutes(1)->command('balabalabala', array('log' => 'balabalabala.log'))->parse()
);
}
public function testFile()
{
$this->assertEquals(
'0 */1 * * * ENV=test HOME=/Users/tom php command.php',
(new Cron())->everyHours(1)->file('command.php')->parse()
);
$this->assertEquals(
'0 */1 * * * ENV=test HOME=/Users/tom php command.php 2>> error.log',
(new Cron())->everyHours(1)->file('command.php', array('error_log' => 'error.log'))->parse()
);
}
}