Skip to content

Commit 3911280

Browse files
authored
Merge pull request #9 from peter279k/test_enhancement
Test enhancement
2 parents 586d7b5 + 5caf431 commit 3911280

File tree

3 files changed

+40
-19
lines changed

3 files changed

+40
-19
lines changed

.travis.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
language: php
22

33
php:
4-
# The adhocore/cron-expr should run fine with php 5.4+, but phpunit 5.7 requires php 5.6+
5-
# - 5.4
6-
# - 5.5
4+
- 5.4
5+
- 5.5
76
- 5.6
87
- 7.0
98
- 7.1
109
- 7.2
10+
- nightly
11+
12+
matrix:
13+
allow_failures:
14+
- php: nightly
1115

1216
install:
1317
- composer install --prefer-dist

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
}
2424
},
2525
"require": {
26+
"php": ">=5.4"
2627
},
2728
"require-dev": {
28-
"phpunit/phpunit": "^5.7.0"
29+
"phpunit/phpunit": "^4.8 || ^5.7 || ^6.5"
2930
}
3031
}

tests/ExpressionTest.php

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,65 @@
33
namespace Ahc\Cron\Test;
44

55
use Ahc\Cron\Expression;
6+
use PHPUnit\Framework\TestCase;
67

7-
class ExpressionTest extends \PHPUnit_Framework_TestCase
8+
class ExpressionTest extends TestCase
89
{
910
/**
1011
* @dataProvider scheduleProvider
1112
*/
1213
public function test_isDue($expr, $time, $foo, $expected, $throwsAt = false)
1314
{
14-
if ($throwsAt) {
15-
$this->setExpectedException(
16-
\UnexpectedValueException::class,
17-
"Invalid offset value at segment #$throwsAt"
18-
);
19-
}
20-
2115
$actual = Expression::isDue($expr, $time);
2216

2317
$this->assertSame($expected, $actual, 'The expression ' . $expr . ' has failed');
2418
}
2519

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+
2629
public function test_isCronDue()
2730
{
2831
$expr = new Expression;
2932

30-
$this->assertTrue(is_bool($expr->isCronDue('*/1 * * * *', time())));
33+
$this->assertInternalType('boolean', $expr->isCronDue('*/1 * * * *', time()));
3134
}
3235

36+
/**
37+
* @expectedException \UnexpectedValueException
38+
*/
3339
public function test_isDue_throws_if_expr_invalid()
3440
{
35-
$this->setExpectedException(\UnexpectedValueException::class);
36-
3741
Expression::isDue('@invalid');
3842
}
3943

44+
/**
45+
* @expectedException \UnexpectedValueException
46+
*/
4047
public function test_isDue_throws_if_modifier_invalid()
4148
{
42-
$this->setExpectedException(\UnexpectedValueException::class);
43-
4449
Expression::isDue('* * 2L * *');
4550
}
4651

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+
4765
/**
4866
* The test cases are taken from awesome mtdowling/cron-expression package. Thank you.
4967
*
@@ -124,8 +142,6 @@ public function scheduleProvider()
124142
['* * * * 5#2', strtotime('2011-07-01 00:00:00'), '2011-07-08 00:00:00', false],
125143
['* * * * 5#1', strtotime('2011-07-01 00:00:00'), '2011-07-01 00:00:00', true],
126144
['* * * * 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
129145
];
130146
}
131147
}

0 commit comments

Comments
 (0)