-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinterTest.php
More file actions
163 lines (145 loc) · 11.2 KB
/
LinterTest.php
File metadata and controls
163 lines (145 loc) · 11.2 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
declare(strict_types=1);
namespace JPI\CronLinter\Tests;
use JPI\CronLinter;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
/**
* @covers \JPI\CronLinter
*/
final class LinterTest extends TestCase {
public static function validProvider(): array {
return [
["* * * * * php test.php"],
["0 * * * * php test.php"],
["10 * * * * php test.php"],
["1,2 * * * * php test.php"],
["15,45 * * * * php test.php"],
["15-45 * * * * php test.php"],
["*/2 * * * * php test.php"],
["1-59/2 * * * * php test.php"],
["* 0 * * * php test.php"],
["* 2 * * * php test.php"],
["* 23 * * * php test.php"],
["* 6,12 * * * php test.php"],
["* 0-6 * * * php test.php"],
["* */3 * * * php test.php"],
["* 0-12/6 * * * php test.php"],
["* * 1 * * php test.php"],
["* * 31 * * php test.php"],
["* * 10,11 * * php test.php"],
["* * 7-21 * * php test.php"],
["* * */5 * * php test.php"],
["* * 21-31/2 * * php test.php"],
["* * * 1 * php test.php"],
["* * * 12 * php test.php"],
["* * * 2,9 * php test.php"],
["* * * 6-9 * php test.php"],
["* * * */2 * php test.php"],
["* * * 6-12/2 * php test.php"],
["* * * feb * php test.php"],
["* * * JUN * php test.php"],
["* * * * 0 php test.php"],
["* * * * 6 php test.php"],
["* * * * 5,4 php test.php"],
["* * * * 2-4 php test.php"],
["* * * * */3 php test.php"],
["* * * * 1-5/4 php test.php"],
["* * * * fri php test.php"],
["* * * * TuE php test.php"],
];
}
#[DataProvider("validProvider")]
public function testValid(string $expression): void {
$errors = CronLinter::lintContent($expression);
$this->assertCount(0, $errors);
}
public static function invalidProvider(): array {
return [
["-0 * * * * php test.php", ["Line 1 contains an invalid value for Minute: -0"]],
["-0-10 * * * * php test.php", ["Line 1 contains an invalid value for Minute: -0"]],
["60 * * * * php test.php", ["Line 1 contains an invalid value for Minute: 60"]],
["59,69 * * * * php test.php", ["Line 1 contains an invalid value for Minute[1]: 69"]],
["60,65 * * * * php test.php", ["Line 1 contains an invalid value for Minute[0]: 60", "Line 1 contains an invalid value for Minute[1]: 65"]],
["15-30-45 * * * * php test.php", ["Line 1 contains an invalid range for Minute: 15-30-45 (too many values)"]],
["*/60 * * * * php test.php", ["Line 1 contains an invalid value for Minute: 60"]],
["55-61/2 * * * * php test.php", ["Line 1 contains an invalid value for Minute: 61"]],
["55-61-63/2 * * * * php test.php", ["Line 1 contains an invalid range for Minute: 55-61-63 (too many values)"]],
["61-62/2 * * * * php test.php", ["Line 1 contains an invalid value for Minute: 61", "Line 1 contains an invalid value for Minute: 62"]],
["1/2 * * * * php test.php", ["Line 1 contains an invalid value for Minute: 1 (must be wildcard `*` or a range)"]],
["*/1/2 * * * * php test.php", ["Line 1 contains too many step values for Minute: */1/2"]],
["2-4-6/2/1 * * * * php test.php", ["Line 1 contains too many step values for Minute: 2-4-6/2/1"]],
["59-0 * * * * php test.php", ["Line 1 contains an invalid range for Minute: 59-0 (must be in ascending order)"]],
["10-9 * * * * php test.php", ["Line 1 contains an invalid range for Minute: 10-9 (must be in ascending order)"]],
["10-9/2 * * * * php test.php", ["Line 1 contains an invalid range for Minute: 10-9 (must be in ascending order)"]],
["60-50 * * * * php test.php", ["Line 1 contains an invalid value for Minute: 60"]],
["* -1 * * * php test.php", ["Line 1 contains an invalid value for Hour: -1"]],
["* -1-23 * * * php test.php", ["Line 1 contains an invalid value for Hour: -1"]],
["* 24 * * * php test.php", ["Line 1 contains an invalid value for Hour: 24"]],
["* 12,24 * * * php test.php", ["Line 1 contains an invalid value for Hour[1]: 24"]],
["* 24,32 * * * php test.php", ["Line 1 contains an invalid value for Hour[0]: 24", "Line 1 contains an invalid value for Hour[1]: 32"]],
["* 6-12-18 * * * php test.php", ["Line 1 contains an invalid range for Hour: 6-12-18 (too many values)"]],
["* */40 * * * php test.php", ["Line 1 contains an invalid value for Hour: 40"]],
["* 23-24/2 * * * php test.php", ["Line 1 contains an invalid value for Hour: 24"]],
["* 24-26/2 * * * php test.php", ["Line 1 contains an invalid value for Hour: 24","Line 1 contains an invalid value for Hour: 26"]],
["* 1/2 * * * php test.php", ["Line 1 contains an invalid value for Hour: 1 (must be wildcard `*` or a range)"]],
["* 1/2/3 * * * php test.php", ["Line 1 contains too many step values for Hour: 1/2/3"]],
["* 23-0 * * * php test.php", ["Line 1 contains an invalid range for Hour: 23-0 (must be in ascending order)"]],
["* 12-5 * * * php test.php", ["Line 1 contains an invalid range for Hour: 12-5 (must be in ascending order)"]],
["* 23-25 * * * php test.php", ["Line 1 contains an invalid value for Hour: 25"]],
["* * -2 * * php test.php", ["Line 1 contains an invalid value for Day of month: -2"]],
["* * -2-14 * * php test.php", ["Line 1 contains an invalid value for Day of month: -2"]],
["* * 0 * * php test.php", ["Line 1 contains an invalid value for Day of month: 0"]],
["* * 32 * * php test.php", ["Line 1 contains an invalid value for Day of month: 32"]],
["* * 28,35 * * php test.php", ["Line 1 contains an invalid value for Day of month[1]: 35"]],
["* * 32,35 * * php test.php", ["Line 1 contains an invalid value for Day of month[0]: 32", "Line 1 contains an invalid value for Day of month[1]: 35"]],
["* * 7-14-21 * * php test.php", ["Line 1 contains an invalid range for Day of month: 7-14-21 (too many values)"]],
["* * */32 * * php test.php", ["Line 1 contains an invalid value for Day of month: 32"]],
["* * 21-35/2 * * php test.php", ["Line 1 contains an invalid value for Day of month: 35"]],
["* * 32-35/2 * * php test.php", ["Line 1 contains an invalid value for Day of month: 32", "Line 1 contains an invalid value for Day of month: 35"]],
["* * 7/14 * * php test.php", ["Line 1 contains an invalid value for Day of month: 7 (must be wildcard `*` or a range)"]],
["* * 7/14/28 * * php test.php", ["Line 1 contains too many step values for Day of month: 7/14/28"]],
["* * 31-1 * * php test.php", ["Line 1 contains an invalid range for Day of month: 31-1 (must be in ascending order)"]],
["* * 31-0 * * php test.php", ["Line 1 contains an invalid value for Day of month: 0"]],
["* * * -3 * php test.php", ["Line 1 contains an invalid value for Month: -3"]],
["* * * -3-12 * php test.php", ["Line 1 contains an invalid value for Month: -3"]],
["* * * 0 * php test.php", ["Line 1 contains an invalid value for Month: 0"]],
["* * * 13 * php test.php", ["Line 1 contains an invalid value for Month: 13"]],
["* * * 3,13 * php test.php", ["Line 1 contains an invalid value for Month[1]: 13"]],
["* * * 13,14 * php test.php", ["Line 1 contains an invalid value for Month[0]: 13", "Line 1 contains an invalid value for Month[1]: 14"]],
["* * * 3-6-9 * php test.php", ["Line 1 contains an invalid range for Month: 3-6-9 (too many values)"]],
["* * * */24 * php test.php", ["Line 1 contains an invalid value for Month: 24"]],
["* * * 8-16/2 * php test.php", ["Line 1 contains an invalid value for Month: 16"]],
["* * * 14-16/2 * php test.php", ["Line 1 contains an invalid value for Month: 14", "Line 1 contains an invalid value for Month: 16"]],
["* * * 8/12 * php test.php", ["Line 1 contains an invalid value for Month: 8 (must be wildcard `*` or a range)"]],
["* * * 8/12/16 * php test.php", ["Line 1 contains too many step values for Month: 8/12/16"]],
["* * * 12-0 * php test.php", ["Line 1 contains an invalid value for Month: 0"]],
["* * * 12-1 * php test.php", ["Line 1 contains an invalid range for Month: 12-1 (must be in ascending order)"]],
["* * * june * php test.php", ["Line 1 contains an invalid value for Month: june"]],
["* * * mar-feb * php test.php", ["Line 1 contains an invalid range for Month: mar-feb (must be numeric)"]],
["* * * * -4 php test.php", ["Line 1 contains an invalid value for Day of week: -4"]],
["* * * * -3-5 php test.php", ["Line 1 contains an invalid value for Day of week: -3"]],
["* * * * 7 php test.php", ["Line 1 contains an invalid value for Day of week: 7"]],
["* * * * 4,8 php test.php", ["Line 1 contains an invalid value for Day of week[1]: 8"]],
["* * * * 7,8 php test.php", ["Line 1 contains an invalid value for Day of week[0]: 7", "Line 1 contains an invalid value for Day of week[1]: 8"]],
["* * * * 2-4-6 php test.php", ["Line 1 contains an invalid range for Day of week: 2-4-6 (too many values)"]],
["* * * * */7 php test.php", ["Line 1 contains an invalid value for Day of week: 7"]],
["* * * * 4-8/2 php test.php", ["Line 1 contains an invalid value for Day of week: 8"]],
["* * * * 8-10/2 php test.php", ["Line 1 contains an invalid value for Day of week: 8", "Line 1 contains an invalid value for Day of week: 10"]],
["* * * * 8/2 php test.php", ["Line 1 contains an invalid value for Day of week: 8 (must be wildcard `*` or a range)"]],
["* * * * 3/6/9 php test.php", ["Line 1 contains too many step values for Day of week: 3/6/9"]],
["* * * * thurs php test.php", ["Line 1 contains an invalid value for Day of week: thurs"]],
["* * * * 6-0 php test.php", ["Line 1 contains an invalid range for Day of week: 6-0 (must be in ascending order)"]],
["* * * * 5-2 php test.php", ["Line 1 contains an invalid range for Day of week: 5-2 (must be in ascending order)"]],
["* * * * 0-mon php test.php", ["Line 1 contains an invalid range for Day of week: 0-mon (must be numeric)"]],
["* * * * fri-mon php test.php", ["Line 1 contains an invalid range for Day of week: fri-mon (must be numeric)"]],
["* * * 18 45 php test.php", ["Line 1 contains an invalid value for Month: 18", "Line 1 contains an invalid value for Day of week: 45"]],
];
}
#[DataProvider("invalidProvider")]
public function testInvalid(string $expression, array $expectedErrors): void {
$errors = CronLinter::lintContent($expression);
$this->assertCount(count($expectedErrors), $errors);
$this->assertSame($expectedErrors, $errors);
}
}