1
+ <?php
2
+
3
+
4
+ namespace ArondeParon \ScheduleWhen \Tests ;
5
+
6
+ use ArondeParon \ScheduleWhen \ScheduleWhen ;
7
+ use Carbon \Carbon ;
8
+ use Illuminate \Console \Command ;
9
+ use Illuminate \Console \Scheduling \Schedule ;
10
+
11
+ class ScheduleWhenTest extends TestCase
12
+ {
13
+ /** @var Schedule */
14
+ protected $ schedule ;
15
+
16
+ /** @var ScheduleWhen */
17
+ protected $ scheduleWhen ;
18
+
19
+ public function test_it_will_return_an_empty_array_if_none_match ()
20
+ {
21
+ $ results = $ this ->scheduleWhen ->handle (Carbon::now ());
22
+
23
+ $ this ->assertCount (0 , $ results );
24
+ }
25
+
26
+ public function test_it_will_return_an_array_of_matched_items ()
27
+ {
28
+ $ mockedCommand = $ this ->mock (Command::class);
29
+ $ anotherCommand = $ this ->mock (Command::class);
30
+
31
+ Carbon::setTestNow (Carbon::now ()->setTimeFromTimeString ('08:00 ' ));
32
+
33
+ $ this ->schedule ->command ($ mockedCommand )
34
+ ->daily ()
35
+ ->at ('08:00 ' );
36
+
37
+ $ this ->schedule ->command ($ anotherCommand )
38
+ ->hourly ();
39
+
40
+ $ results = $ this ->scheduleWhen ->handle (Carbon::now ());
41
+
42
+ $ this ->assertCount (2 , $ results );
43
+ }
44
+
45
+ public function test_it_will_not_return_items_that_occur_on_other_intervals ()
46
+ {
47
+ $ mockedCommand = $ this ->mock (Command::class);
48
+ $ anotherCommand = $ this ->mock (Command::class);
49
+ $ someOtherCommand = $ this ->mock (Command::class);
50
+
51
+ Carbon::setTestNow (Carbon::now ()->setTimeFromTimeString ('08:00 ' ));
52
+
53
+ $ this ->schedule ->command ($ mockedCommand )
54
+ ->daily ()
55
+ ->at ('08:00 ' );
56
+
57
+ $ this ->schedule ->command ($ anotherCommand )
58
+ ->hourly ();
59
+
60
+ $ this ->schedule ->command ($ someOtherCommand )
61
+ ->dailyAt ('08:01 ' );
62
+
63
+ $ results = $ this ->scheduleWhen ->handle (Carbon::now ());
64
+
65
+ $ this ->assertCount (2 , $ results );
66
+ }
67
+
68
+ public function setUp (): void
69
+ {
70
+ parent ::setUp ();
71
+
72
+ $ this ->schedule = app (Schedule::class);
73
+ $ this ->scheduleWhen = app (ScheduleWhen::class);
74
+ }
75
+ }
0 commit comments