stateful example

        $now = self::makeDateTime($startTime);

        $clock = $this->createMock(ClockInterface::class);
        $clock->method('now')->willReturnReference($now);

        foreach ($schedule as $i => $s) {
            if (\is_array($s)) {
                $schedule[$i] = $this->createMessage(...$s);
            }
        }
        $schedule = (new Schedule())->add(...$schedule);
        $schedule->stateful(new ArrayAdapter());

        $scheduler = new MessageGenerator($schedule, 'dummy', $clock);

        // Warmup. The first run always returns nothing.         $this->assertSame([]iterator_to_array($scheduler->getMessages(), false));

        foreach ($runs as $time => $expected) {
            $now = self::makeDateTime($time);
            $this->assertSame($expectediterator_to_array($scheduler->getMessages(), false));
        }
    }

    
use Symfony\Component\Scheduler\ScheduleProviderInterface;

#[AsSchedule('dummy')] class DummySchedule implements ScheduleProviderInterface
{
    public static array $recurringMessages;

    public function getSchedule(): Schedule
    {
        return (new Schedule())
            ->add(...self::$recurringMessages)
            ->stateful(new ArrayAdapter())
            ->lock(new Lock(new Key('dummy')new InMemoryStore()))
        ;
    }
}
Home | Imprint | This part of the site doesn't use cookies.