CronExpression example

$this->definitionInstanceRegistry = $this->createMock(DefinitionInstanceRegistry::class);
        $this->validator = $this->createMock(ValidatorInterface::class);

        $this->intervalFieldSerializer = new CronIntervalFieldSerializer(
            $this->validator,
            $this->definitionInstanceRegistry
        );
    }

    public function testEncodeMethodWithCorrectDataWillReturnCronIntervalString(): void
    {
        $data = new KeyValuePair('key', new CronExpression(self::COMPLEX_CRON), false);

        $cronExpression = $this->intervalFieldSerializer->encode(
            new CronIntervalField('fake', 'fake'),
            $this->createStub(EntityExistence::class),
            $data,
            $this->createMock(WriteParameterBag::class)
        )->current();

        static::assertIsString($cronExpression);
        static::assertEquals(self::COMPLEX_CRON, $cronExpression);
    }

    
if ($interval === null) {
            yield $field->getStorageName() => null;

            return;
        }

        if (\is_string($interval)) {
            if (!CronExpression::isValidExpression($interval)) {
                throw DataAbstractionLayerException::invalidCronIntervalFormat($interval);
            }

            $interval = new CronExpression($interval);
        }

        $data->setValue($interval);
        $this->validateIfNeeded($field$existence$data$parameters);

        if (!$interval instanceof CronExpression) {
            yield $field->getStorageName() => null;

            return;
        }

        
static::assertTrue($cronInterval->isEmpty());
    }

    public function testNotIsEmpty(): void
    {
        $cronInterval = new CronInterval('0 * * * *');
        static::assertFalse($cronInterval->isEmpty());
    }

    public function testCreateFromCronExpression(): void
    {
        $cronExpression = new CronExpression('0 * * * *');
        $cronInterval = CronInterval::createFromCronExpression($cronExpression);
        static::assertSame($cronInterval->getExpression()$cronExpression->getExpression());
    }
}
private const HASH_RANGES = [
        [0, 59],
        [0, 23],
        [1, 28],
        [1, 12],
        [0, 6],
    ];

    private readonly ?string $timezone;

    public function __construct(
        private readonly CronExpression $expression = new CronExpression('* * * * *'),
        \DateTimeZone|string $timezone = null,
    ) {
        $this->timezone = $timezone instanceof \DateTimeZone ? $timezone->getName() : $timezone;
    }

    public function __toString(): string
    {
        return $this->expression->getExpression();
    }

    public static function fromSpec(string $expression = '* * * * *', string $context = null, \DateTimeZone|string $timezone = null): self
    {
Home | Imprint | This part of the site doesn't use cookies.