2 declare(strict_types = 1);
19 use PHPUnit\Framework\Constraint\IsType;
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
35 '@weekly' => [
'@weekly',
'0 0 * * 7'],
36 ' @weekly ' => [
' @weekly ',
'0 0 * * 7'],
37 '* * * * *' => [
'* * * * *',
'* * * * *'],
38 '30 4 1,15 * 5' => [
'30 4 1,15 * 5',
'30 4 1,15 * 5'],
39 '5 0 * * *' => [
'5 0 * * *',
'5 0 * * *'],
40 '15 14 1 * *' => [
'15 14 1 * *',
'15 14 1 * *'],
41 '0 22 * * 1-5' => [
'0 22 * * 1-5',
'0 22 * * 1,2,3,4,5'],
42 '23 0-23/2 * * *' => [
'23 0-23/2 * * *',
'23 0,2,4,6,8,10,12,14,16,18,20,22 * * *'],
43 '5 4 * * sun' => [
'5 4 * * sun',
'5 4 * * 7'],
44 '0-3/2,7 0,4 20-22, feb,mar-jun/2,7 1-3,sun' => [
45 '0-3/2,7 0,4 20-22 feb,mar-jun/2,7 1-3,sun',
46 '0,2,7 0,4 20,21,22 2,3,5,7 1,2,3,7'
48 '0-20/10 * * * *' => [
'0-20/10 * * * *',
'0,10,20 * * * *'],
49 '* * 2 * *' => [
'* * 2 * *',
'* * 2 * *'],
50 '* * 2,7 * *' => [
'* * 2,7 * *',
'* * 2,7 * *'],
51 '* * 2-4,10 * *' => [
'* * 2-4,10 * *',
'* * 2,3,4,10 * *'],
52 '* * */14 * *' => [
'* * */14 * *',
'* * 1,15,29 * *'],
53 '* * 2,4-6/2,*/14 * *' => [
'* * 2,4-6/2,*/14 * *',
'* * 1,2,4,6,15,29 * *'],
54 '* * * * 1' => [
'* * * * 1',
'* * * * 1'],
55 '0 0 * * 0' => [
'0 0 * * 0',
'0 0 * * 7'],
56 '0 0 * * 7' => [
'0 0 * * 7',
'0 0 * * 7'],
57 '* * 1,2 * 1' => [
'* * 1,2 * 1',
'* * 1,2 * 1'],
58 '15 02 * * *' => [
'15 02 * * *',
'15 2 * * *'],
59 '08 02 * * *' => [
'08 02 * * *',
'8 2 * * *'],
60 '15 00 * * *' => [
'15 00 * * *',
'15 0 * * *']
73 $this->assertEquals($expected, $result);
82 '@yearly' => [
'@yearly',
'0 0 1 1 *'],
83 '@annually' => [
'@annually',
'0 0 1 1 *'],
84 '@monthly' => [
'@monthly',
'0 0 1 * *'],
85 '@weekly' => [
'@weekly',
'0 0 * * 0'],
86 '@daily' => [
'@daily',
'0 0 * * *'],
87 '@midnight' => [
'@midnight',
'0 0 * * *'],
88 '@hourly' => [
'@hourly',
'0 * * * *']
101 $this->assertEquals($expectedCronCommand, $result);
109 $invalidKeyword =
'foo';
111 $this->assertEquals($invalidKeyword, $result);
120 '1-2 * * * *' => [
'1-2 * * * *',
'1,2 * * * *'],
121 '* 1-2 * * *' => [
'* 1-2 * * *',
'* 1,2 * * *'],
122 '* * 1-2 * *' => [
'* * 1-2 * *',
'* * 1,2 * *'],
123 '* * * 1-2 *' => [
'* * * 1-2 *',
'* * * 1,2 *'],
124 '* * * * 1-2' => [
'* * * * 1-2',
'* * * * 1,2']
137 $this->assertEquals($expected, $result);
146 '* monthField' => [
'*',
true,
'*'],
147 'string 1 monthField' => [
'1',
true,
'1'],
148 'jan' => [
'jan',
true,
'1'],
149 'feb/2' => [
'feb/2',
true,
'2'],
150 'jan-feb/2' => [
'jan-feb/2',
true,
'1'],
151 '1-2 monthField' => [
'1-2',
true,
'1,2'],
152 '1-3/2,feb,may,6' => [
'1-3/2,feb,may,6',
true,
'1,2,3,5,6'],
153 '*/4' => [
'*/4',
true,
'1,5,9'],
154 '* !monthField' => [
'*',
false,
'*'],
155 'string 1, !monthField' => [
'1',
false,
'1'],
156 'fri' => [
'fri',
false,
'5'],
157 'sun' => [
'sun',
false,
'7'],
158 'string 0 for sunday' => [
'0',
false,
'7'],
159 '0,1' => [
'0,1',
false,
'1,7'],
160 '*/3' => [
'*/3',
false,
'1,4,7'],
161 'tue/2' => [
'tue/2',
false,
'2'],
162 '1-2 !monthField' => [
'1-2',
false,
'1,2'],
163 'tue-fri/2' => [
'tue-fri/2',
false,
'2,4'],
164 '1-3/2,tue,fri,6' => [
'1-3/2,tue,fri,6',
false,
'1,2,3,5,6']
181 $this->assertSame($expected, $result);
190 'mon' => [
'mon',
true, 1291083486],
191 '1-2/mon' => [
'1-2/mon',
true, 1291414957],
192 '0,1' => [
'0,1',
true, 1291083486],
193 'feb' => [
'feb',
false, 1291163589],
194 '1-2/feb' => [
'1-2/feb',
false, 1291414957],
195 '0-fri/2,7' => [
'0-fri/2,7',
false, 1291237145]
209 $expectedExceptionCode
211 $this->expectException(\InvalidArgumentException::class);
212 $this->expectExceptionCode($expectedExceptionCode);
223 'string 2' => [
'2',
'2'],
224 'integer 3' => [3,
'3'],
225 'list of values' => [
'1,2,3',
'1,2,3'],
226 'unsorted list of values' => [
'3,1,5',
'1,3,5'],
227 'duplicate values' => [
'0-2/2,2',
'0,2'],
228 'additional field between steps' => [
'1-3/2,2',
'1,2,3'],
229 '2-4' => [
'2-4',
'2,3,4'],
230 'simple step 4/4' => [
'4/4',
'4'],
231 'step 2-7/5' => [
'2-7/5',
'2,7'],
232 'steps 4-12/4' => [
'4-12/4',
'4,8,12'],
233 '0-59/20' => [
'0-59/20',
'0,20,40'],
234 '*/20' => [
'*/20',
'0,20,40']
247 $this->assertSame($expected, $result);
256 'string foo' => [
'foo', 0, 59, 1291429389],
257 'empty string' => [
'', 0, 59, 1291429389],
258 '4-3' => [
'4-3', 0, 59, 1291237145],
259 '/2' => [
'/2', 0, 59, 1291234985],
260 '/' => [
'/', 0, 59, 1291234985],
261 'left bound too low' => [
'2-4', 3, 4, 1291470084],
262 'right bound too high' => [
'2-4', 2, 3, 1291470170],
263 'left and right bound' => [
'2-5', 2, 4, 1291470170],
264 'element in list is lower than allowed' => [
'2,1,4', 2, 4, 1291470084],
265 'element in list is higher than allowed' => [
'2,5,4', 1, 4, 1291470170]
281 $expectedExceptionCode
283 $this->expectException(\InvalidArgumentException::class);
284 $this->expectExceptionCode($expectedExceptionCode);
302 $this->assertSame($expectedResult, $result);
311 'empty string' => [
''],
314 'four fields' => [
'* * * *'],
315 'six fields' => [
'* * * * * *']
326 $this->expectException(\InvalidArgumentException::class);
327 $this->expectExceptionCode(1291227373);
337 'single value' => [
'3',
'3'],
338 'integer 3' => [3,
'3'],
339 '0-0' => [
'0-0',
'0'],
340 '4-4' => [
'4-4',
'4'],
341 '0-3' => [
'0-3',
'0,1,2,3'],
342 '4-5' => [
'4-5',
'4,5']
355 $this->assertSame($expected, $result);
364 'empty string' => [
'', 1291234985],
365 'string' => [
'foo', 1291237668],
366 'single dash' => [
'-', 1291237668],
367 'left part is string' => [
'foo-5', 1291237668],
368 'right part is string' => [
'5-foo', 1291237668],
369 'range of strings' => [
'foo-bar', 1291237668],
370 'string five minus' => [
'5-', 1291237668],
371 'string minus five' => [
'-5', 1291237668],
372 'more than one dash' => [
'2-3-4', 1291234986],
373 'left part bigger than right part' => [
'6-3', 1291237145]
385 $this->expectException(\InvalidArgumentException::class);
386 $this->expectExceptionCode($expectedExceptionCode);
396 '2/2' => [
'2/2',
'2'],
397 '2,3,4/2' => [
'2,3,4/2',
'2,4'],
398 '1,2,3,4,5,6,7/3' => [
'1,2,3,4,5,6,7/3',
'1,4,7'],
399 '0,1,2,3,4,5,6/3' => [
'0,1,2,3,4,5,6/3',
'0,3,6']
412 $this->assertSame($expected, $result);
421 'empty string' => [
'', 1291234987],
422 'slash only' => [
'/', 1291414955],
423 'left part empty' => [
'/2', 1291414955],
424 'right part empty' => [
'2/', 1291414956],
425 'multiples slashes' => [
'1/2/3', 1291242168],
426 '2-2' => [
'2-2', 1291414956],
427 '2.3/2' => [
'2.3/2', 1291414958],
428 '2,3,4/2.3' => [
'2,3,4/2.3', 1291414957],
429 '2,3,4/2,3' => [
'2,3,4/2,3', 1291414957]
441 $expectedExceptionCode
443 $this->expectException(\InvalidArgumentException::class);
444 $this->expectExceptionCode($expectedExceptionCode);
455 $this->assertSame(
'2', $result);
464 $this->assertSame(
'5', $result);
473 $this->assertSame(
'2', $result);
491 'oct' => [
'oct', 10],
492 'nov' => [
'nov', 11],
493 'dec' => [
'dec', 12],
494 'string 7' => [
'7', 7],
495 'integer 7' => [7, 7],
496 'string 07' => [
'07', 7],
497 'integer 07' => [7, 7]
510 $this->assertEquals($expectedInteger, $result);
522 $this->assertInternalType(IsType::TYPE_INT, $result);
531 'sep-' => [
'sep-', 1291083486],
532 '-September-' => [
'-September-', 1291083486],
533 ',sep' => [
',sep', 1291083486],
534 ',September,' => [
',September,', 1291083486],
535 'sep/' => [
'sep/', 1291083486],
536 '/sep' => [
'/sep', 1291083486],
537 '/September/' => [
'/September/', 1291083486],
538 'foo' => [
'foo', 1291083486],
539 'Tuesday' => [
'Tuesday', 1291083486],
540 'Tue' => [
'Tue', 1291083486],
541 'string 0' => [
'0', 1291083486],
542 'integer 0' => [0, 1291083486],
543 'string seven' => [
'seven', 1291083486],
544 'string 13' => [
'13', 1291083486],
545 'integer 13' => [13, 1291083486],
546 'integer 100' => [100, 1291083486],
547 'integer 2010' => [2010, 1291083486],
548 'string minus 7' => [
'-7', 1291083486],
549 'negative integer 7' => [-7, 1291083486]
561 $expectedExceptionCode
563 $this->expectException(\InvalidArgumentException::class);
564 $this->expectExceptionCode($expectedExceptionCode);
575 'string 1' => [
'1', 1],
576 'string 2' => [
'2', 2],
577 'string 02' => [
'02', 2],
578 'integer 02' => [2, 2],
579 'string 3' => [
'3', 3],
580 'string 4' => [
'4', 4],
581 'string 5' => [
'5', 5],
582 'integer 5' => [5, 5],
583 'string 6' => [
'6', 6],
584 'string 7' => [
'7', 7],
585 'string 0' => [
'0', 7],
586 'integer 0' => [0, 7],
588 'monday' => [
'monday', 1],
590 'tuesday' => [
'tuesday', 2],
592 'WEDnesday' => [
'WEDnesday', 3],
594 'Thursday' => [
'Thursday', 4],
596 'friday' => [
'friday', 5],
598 'saturday' => [
'saturday', 6],
600 'sunday' => [
'sunday', 7]
613 $this->assertEquals($expectedInteger, $result);
625 $this->assertInternalType(IsType::TYPE_INT, $result);
636 '-friday-' => [
'-friday-'],
639 '/friday/' => [
'/friday/'],
641 ',friday,' => [
',friday,'],
642 'string minus 1' => [
'-1'],
643 'integer -1' => [-1],
644 'string seven' => [
'seven'],
646 'string 29' => [
'29'],
647 'string 2010' => [
'2010'],
649 'January' => [
'January'],
661 $this->expectException(\InvalidArgumentException::class);
662 $this->expectExceptionCode(1291163589);