1313
1414use PHPUnit \Framework \TestCase ;
1515use Symfony \Component \Cache \Adapter \ArrayAdapter ;
16- use Symfony \Component \Clock \ClockInterface ;
1716use Symfony \Component \Clock \MockClock ;
1817use Symfony \Component \Scheduler \Generator \Checkpoint ;
1918use Symfony \Component \Scheduler \Generator \MessageContext ;
@@ -30,11 +29,7 @@ class MessageGeneratorTest extends TestCase
3029 */
3130 public function testGetMessagesFromSchedule (string $ startTime , array $ runs , array $ schedule )
3231 {
33- // for referencing
34- $ now = self ::makeDateTime ($ startTime );
35-
36- $ clock = $ this ->createMock (ClockInterface::class);
37- $ clock ->method ('now ' )->willReturnReference ($ now );
32+ $ clock = new MockClock (self ::makeDateTime ($ startTime ));
3833
3934 foreach ($ schedule as $ i => $ s ) {
4035 if (\is_array ($ s )) {
@@ -50,7 +45,7 @@ public function testGetMessagesFromSchedule(string $startTime, array $runs, arra
5045 $ this ->assertSame ([], iterator_to_array ($ scheduler ->getMessages (), false ));
5146
5247 foreach ($ runs as $ time => $ expected ) {
53- $ now = self :: makeDateTime ($ time );
48+ $ clock -> modify ($ time );
5449 $ this ->assertSame ($ expected , iterator_to_array ($ scheduler ->getMessages (), false ));
5550 }
5651 }
@@ -60,11 +55,7 @@ public function testGetMessagesFromSchedule(string $startTime, array $runs, arra
6055 */
6156 public function testGetMessagesFromScheduleProvider (string $ startTime , array $ runs , array $ schedule )
6257 {
63- // for referencing
64- $ now = self ::makeDateTime ($ startTime );
65-
66- $ clock = $ this ->createMock (ClockInterface::class);
67- $ clock ->method ('now ' )->willReturnReference ($ now );
58+ $ clock = new MockClock (self ::makeDateTime ($ startTime ));
6859
6960 foreach ($ schedule as $ i => $ s ) {
7061 if (\is_array ($ s )) {
@@ -92,18 +83,14 @@ public function getSchedule(): Schedule
9283 $ this ->assertSame ([], iterator_to_array ($ scheduler ->getMessages (), false ));
9384
9485 foreach ($ runs as $ time => $ expected ) {
95- $ now = self :: makeDateTime ($ time );
86+ $ clock -> modify ($ time );
9687 $ this ->assertSame ($ expected , iterator_to_array ($ scheduler ->getMessages (), false ));
9788 }
9889 }
9990
10091 public function testYieldedContext ()
10192 {
102- // for referencing
103- $ now = self ::makeDateTime ('22:12:00 ' );
104-
105- $ clock = $ this ->createMock (ClockInterface::class);
106- $ clock ->method ('now ' )->willReturnReference ($ now );
93+ $ clock = new MockClock (self ::makeDateTime ('22:12:00 ' ));
10794
10895 $ message = $ this ->createMessage ((object ) ['id ' => 'message ' ], '22:13:00 ' , '22:14:00 ' , '22:16:00 ' );
10996 $ schedule = (new Schedule ())->add ($ message );
@@ -114,8 +101,7 @@ public function testYieldedContext()
114101 // Warmup. The first run is alw ays returns nothing.
115102 $ this ->assertSame ([], iterator_to_array ($ scheduler ->getMessages (), false ));
116103
117- $ now = self ::makeDateTime ('22:14:10 ' );
118-
104+ $ clock ->sleep (2 * 60 + 10 );
119105 $ iterator = $ scheduler ->getMessages ();
120106
121107 $ this ->assertInstanceOf (MessageContext::class, $ context = $ iterator ->key ());
0 commit comments