1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Zenstruck\ScheduleBundle\Tests\Schedule\Extension; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
6
|
|
|
use Zenstruck\ScheduleBundle\Tests\Fixture\MockScheduleBuilder; |
7
|
|
|
use Zenstruck\ScheduleBundle\Tests\Fixture\MockTask; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @author Kevin Bond <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
final class BetweenTimeExtensionTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @test |
16
|
|
|
* @dataProvider onlyBetweenExtensionSkipProvider |
17
|
|
|
*/ |
18
|
|
|
public function only_between_extension_skip($start, $end, $inclusive) |
19
|
|
|
{ |
20
|
|
|
$start = (new \DateTime($start))->format('H:i'); |
21
|
|
|
$end = (new \DateTime($end))->format('H:i'); |
22
|
|
|
$task = (new MockTask())->onlyBetween($start, $end, $inclusive); |
23
|
|
|
|
24
|
|
|
$context = (new MockScheduleBuilder())->addTask($task)->run(); |
25
|
|
|
|
26
|
|
|
$this->assertCount(0, $context->getRun()); |
27
|
|
|
$this->assertCount(1, $skipped = $context->getSkipped()); |
28
|
|
|
$this->assertSame("Only runs between {$start} and {$end}", $skipped[0]->getDescription()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public static function onlyBetweenExtensionSkipProvider() |
32
|
|
|
{ |
33
|
|
|
return [ |
34
|
|
|
['+2 minutes', '+3 minutes', true], |
35
|
|
|
['now', '+3 minutes', false], |
36
|
|
|
['+5 minutes', '+23 hours', true], |
37
|
|
|
]; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @test |
42
|
|
|
* @dataProvider onlyBetweenExtensionRunProvider |
43
|
|
|
*/ |
44
|
|
|
public function only_between_extension_run($start, $end, $inclusive) |
45
|
|
|
{ |
46
|
|
|
$start = (new \DateTime($start))->format('H:i'); |
47
|
|
|
$end = (new \DateTime($end))->format('H:i'); |
48
|
|
|
$task = (new MockTask())->onlyBetween($start, $end, $inclusive); |
49
|
|
|
|
50
|
|
|
$context = (new MockScheduleBuilder())->addTask($task)->run(); |
51
|
|
|
|
52
|
|
|
$this->assertCount(1, $context->getRun()); |
53
|
|
|
$this->assertCount(0, $context->getSkipped()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public static function onlyBetweenExtensionRunProvider() |
57
|
|
|
{ |
58
|
|
|
return [ |
59
|
|
|
['now', '+3 minutes', true], |
60
|
|
|
['-1 minute', '+3 minutes', false], |
61
|
|
|
['-1 minutes', '+23 hours', true], |
62
|
|
|
]; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @test |
67
|
|
|
* @dataProvider unlessBetweenExtensionSkipProvider |
68
|
|
|
*/ |
69
|
|
|
public function unless_between_extension_skip($start, $end, $inclusive) |
70
|
|
|
{ |
71
|
|
|
$start = (new \DateTime($start))->format('H:i'); |
72
|
|
|
$end = (new \DateTime($end))->format('H:i'); |
73
|
|
|
$task = (new MockTask())->unlessBetween($start, $end, $inclusive); |
74
|
|
|
|
75
|
|
|
$context = (new MockScheduleBuilder())->addTask($task)->run(); |
76
|
|
|
|
77
|
|
|
$this->assertCount(0, $context->getRun()); |
78
|
|
|
$this->assertCount(1, $skipped = $context->getSkipped()); |
79
|
|
|
$this->assertSame("Only runs if not between {$start} and {$end}", $skipped[0]->getDescription()); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public static function unlessBetweenExtensionSkipProvider() |
83
|
|
|
{ |
84
|
|
|
return [ |
85
|
|
|
['-1 minute', '+3 minutes', false], |
86
|
|
|
['now', '+3 minutes', true], |
87
|
|
|
['-1 minutes', '+23 hours', true], |
88
|
|
|
]; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @test |
93
|
|
|
* @dataProvider unlessBetweenExtensionRunProvider |
94
|
|
|
*/ |
95
|
|
|
public function unless_between_extension_run($start, $end, $inclusive) |
96
|
|
|
{ |
97
|
|
|
$start = (new \DateTime($start))->format('H:i'); |
98
|
|
|
$end = (new \DateTime($end))->format('H:i'); |
99
|
|
|
$task = (new MockTask())->unlessBetween($start, $end, $inclusive); |
100
|
|
|
|
101
|
|
|
$context = (new MockScheduleBuilder())->addTask($task)->run(); |
102
|
|
|
|
103
|
|
|
$this->assertCount(1, $context->getRun()); |
104
|
|
|
$this->assertCount(0, $context->getSkipped()); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public static function unlessBetweenExtensionRunProvider() |
108
|
|
|
{ |
109
|
|
|
return [ |
110
|
|
|
['now', '+3 minutes', false], |
111
|
|
|
['+1 minute', '+3 minutes', true], |
112
|
|
|
['+5 minutes', '+23 hours', true], |
113
|
|
|
]; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths