|
3 | 3 | namespace Ahc\Cron\Test; |
4 | 4 |
|
5 | 5 | use Ahc\Cron\Expression; |
| 6 | +use PHPUnit\Framework\TestCase; |
6 | 7 |
|
7 | | -class ExpressionTest extends \PHPUnit_Framework_TestCase |
| 8 | +class ExpressionTest extends TestCase |
8 | 9 | { |
9 | 10 | /** |
10 | 11 | * @dataProvider scheduleProvider |
11 | 12 | */ |
12 | 13 | public function test_isDue($expr, $time, $foo, $expected, $throwsAt = false) |
13 | 14 | { |
14 | | - if ($throwsAt) { |
15 | | - $this->setExpectedException( |
16 | | - \UnexpectedValueException::class, |
17 | | - "Invalid offset value at segment #$throwsAt" |
18 | | - ); |
19 | | - } |
20 | | - |
21 | 15 | $actual = Expression::isDue($expr, $time); |
22 | 16 |
|
23 | 17 | $this->assertSame($expected, $actual, 'The expression ' . $expr . ' has failed'); |
24 | 18 | } |
25 | 19 |
|
| 20 | + /** |
| 21 | + * @dataProvider invalidScheduleProvider |
| 22 | + * @expectedException \UnexpectedValueException |
| 23 | + */ |
| 24 | + public function test_isDue_on_invalid_expression($expr, $time, $foo, $expected, $throwsAt = false) |
| 25 | + { |
| 26 | + Expression::isDue($expr, $time); |
| 27 | + } |
| 28 | + |
26 | 29 | public function test_isCronDue() |
27 | 30 | { |
28 | 31 | $expr = new Expression; |
29 | 32 |
|
30 | | - $this->assertTrue(is_bool($expr->isCronDue('*/1 * * * *', time()))); |
| 33 | + $this->assertInternalType('boolean', $expr->isCronDue('*/1 * * * *', time())); |
31 | 34 | } |
32 | 35 |
|
| 36 | + /** |
| 37 | + * @expectedException \UnexpectedValueException |
| 38 | + */ |
33 | 39 | public function test_isDue_throws_if_expr_invalid() |
34 | 40 | { |
35 | | - $this->setExpectedException(\UnexpectedValueException::class); |
36 | | - |
37 | 41 | Expression::isDue('@invalid'); |
38 | 42 | } |
39 | 43 |
|
| 44 | + /** |
| 45 | + * @expectedException \UnexpectedValueException |
| 46 | + */ |
40 | 47 | public function test_isDue_throws_if_modifier_invalid() |
41 | 48 | { |
42 | | - $this->setExpectedException(\UnexpectedValueException::class); |
43 | | - |
44 | 49 | Expression::isDue('* * 2L * *'); |
45 | 50 | } |
46 | 51 |
|
| 52 | + /** |
| 53 | + * Data provider for cron schedule. |
| 54 | + * |
| 55 | + * @return array |
| 56 | + */ |
| 57 | + public function invalidScheduleProvider() |
| 58 | + { |
| 59 | + return [ |
| 60 | + ['* * * * 4W', strtotime('2011-07-01 00:00:00'), '2011-07-27 00:00:00', false, 4], // seg 4 |
| 61 | + ['* * * 1L *', strtotime('2011-07-01 00:00:00'), '2011-07-27 00:00:00', false, 3], // seg 3 |
| 62 | + ]; |
| 63 | + } |
| 64 | + |
47 | 65 | /** |
48 | 66 | * The test cases are taken from awesome mtdowling/cron-expression package. Thank you. |
49 | 67 | * |
@@ -124,8 +142,6 @@ public function scheduleProvider() |
124 | 142 | ['* * * * 5#2', strtotime('2011-07-01 00:00:00'), '2011-07-08 00:00:00', false], |
125 | 143 | ['* * * * 5#1', strtotime('2011-07-01 00:00:00'), '2011-07-01 00:00:00', true], |
126 | 144 | ['* * * * 3#4', strtotime('2011-07-01 00:00:00'), '2011-07-27 00:00:00', false], |
127 | | - ['* * * * 4W', strtotime('2011-07-01 00:00:00'), '2011-07-27 00:00:00', false, 4], // seg 4 |
128 | | - ['* * * 1L *', strtotime('2011-07-01 00:00:00'), '2011-07-27 00:00:00', false, 3], // seg 3 |
129 | 145 | ]; |
130 | 146 | } |
131 | 147 | } |
0 commit comments