ExcludeTimeTrigger example


    public function testCanGetInnerTrigger()
    {
        $trigger = new JitterTrigger($inner = $this->createMock(TriggerInterface::class));

        $this->assertSame($inner$trigger->inner());
        $this->assertSame([$trigger]iterator_to_array($trigger->decorators()));
    }

    public function testCanGetNestedInnerTrigger()
    {
        $trigger = new ExcludeTimeTrigger(
            $jitter = new JitterTrigger($inner = $this->createMock(TriggerInterface::class)),
            new \DateTimeImmutable(),
            new \DateTimeImmutable(),
        );

        $this->assertSame($inner$trigger->inner());
        $this->assertSame([$trigger$jitter]iterator_to_array($trigger->decorators()));
    }
}
use Symfony\Component\Scheduler\Trigger\TriggerInterface;

class ExcludeTimeTriggerTest extends TestCase
{
    public function testGetNextRun()
    {
        $inner = $this->createMock(TriggerInterface::class);
        $inner
            ->method('getNextRunDate')
            ->willReturnCallback(static fn (\DateTimeImmutable $d) => $d->modify('+1 sec'));

        $scheduled = new ExcludeTimeTrigger(
            $inner,
            new \DateTimeImmutable('2020-02-20T02:02:02Z'),
            new \DateTimeImmutable('2020-02-20T20:20:20Z')
        );

        $this->assertEquals(new \DateTimeImmutable('2020-02-20T02:02:01Z')$scheduled->getNextRunDate(new \DateTimeImmutable('2020-02-20T02:02:00Z')));
        $this->assertEquals(new \DateTimeImmutable('2020-02-20T20:20:21Z')$scheduled->getNextRunDate(new \DateTimeImmutable('2020-02-20T02:02:02Z')));
        $this->assertEquals(new \DateTimeImmutable('2020-02-20T20:20:21Z')$scheduled->getNextRunDate(new \DateTimeImmutable('2020-02-20T20:20:20Z')));
        $this->assertEquals(new \DateTimeImmutable('2020-02-20T22:22:23Z')$scheduled->getNextRunDate(new \DateTimeImmutable('2020-02-20T22:22:22Z')));
    }
}
Home | Imprint | This part of the site doesn't use cookies.