File tree 1 file changed +49
-0
lines changed
src/Symfony/Component/Scheduler/Tests
1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony \Component \Scheduler \Tests ;
13
+
14
+ use PHPUnit \Framework \TestCase ;
15
+ use Symfony \Component \Scheduler \RecurringMessage ;
16
+ use Symfony \Component \Scheduler \Schedule ;
17
+ use Symfony \Component \Scheduler \Scheduler ;
18
+
19
+ class SchedulerTest extends TestCase
20
+ {
21
+ public function testCanRunAndStop ()
22
+ {
23
+ $ handler = new Handler ();
24
+ $ schedule = (new Schedule ())->add (RecurringMessage::every ('1 millisecond ' , new Message ()));
25
+ $ scheduler = new Scheduler ([Message::class => $ handler ], [$ schedule ]);
26
+ $ handler ->scheduler = $ scheduler ;
27
+
28
+ $ scheduler ->run (['sleep ' => 0 ]);
29
+
30
+ $ this ->assertSame (3 , $ handler ->count );
31
+ }
32
+ }
33
+
34
+ class Message
35
+ {
36
+ }
37
+
38
+ class Handler
39
+ {
40
+ public int $ count = 0 ;
41
+ public Scheduler $ scheduler ;
42
+
43
+ public function __invoke (Message $ message ): void
44
+ {
45
+ if (3 === ++$ this ->count ) {
46
+ $ this ->scheduler ->stop ();
47
+ }
48
+ }
49
+ }
You can’t perform that action at this time.
0 commit comments