diff --git a/src/Symfony/Component/Scheduler/Tests/Trigger/PeriodicalTriggerTest.php b/src/Symfony/Component/Scheduler/Tests/Trigger/PeriodicalTriggerTest.php index a6deba05b6fe4..22162e792fa24 100644 --- a/src/Symfony/Component/Scheduler/Tests/Trigger/PeriodicalTriggerTest.php +++ b/src/Symfony/Component/Scheduler/Tests/Trigger/PeriodicalTriggerTest.php @@ -60,21 +60,22 @@ public static function provideForConstructor(): iterable /** * @dataProvider getInvalidIntervals */ - public function testInvalidInterval($interval) + public function testInvalidInterval($interval, $expectedExceptionMessage) { $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage($expectedExceptionMessage); new PeriodicalTrigger($interval, $now = new \DateTimeImmutable(), $now->modify('1 day')); } public static function getInvalidIntervals(): iterable { - yield ['wrong']; - yield ['3600.5']; - yield ['-3600']; - yield [-3600]; - yield ['0']; - yield [0]; + yield ['wrong', 'Unknown or bad format (wrong) at position 0 (w): The timezone could not be found in the database']; + yield ['3600.5', 'Unknown or bad format (3600.5) at position 5 (5): Unexpected character']; + yield ['-3600', 'Unknown or bad format (-3600) at position 3 (0): Unexpected character']; + yield [-3600, 'The "$interval" argument must be greater than zero.']; + yield ['0', 'The "$interval" argument must be greater than zero.']; + yield [0, 'The "$interval" argument must be greater than zero.']; } /** diff --git a/src/Symfony/Component/Scheduler/Trigger/PeriodicalTrigger.php b/src/Symfony/Component/Scheduler/Trigger/PeriodicalTrigger.php index fb5cfc957536c..177737a7955d3 100644 --- a/src/Symfony/Component/Scheduler/Trigger/PeriodicalTrigger.php +++ b/src/Symfony/Component/Scheduler/Trigger/PeriodicalTrigger.php @@ -52,7 +52,11 @@ public function __construct( $i = $interval; if (\is_string($interval)) { $this->description = sprintf('every %s', $interval); - $i = \DateInterval::createFromDateString($interval); + $i = @\DateInterval::createFromDateString($interval); + + if (false === $i) { + throw new InvalidArgumentException(sprintf('Invalid interval "%s": ', $interval).error_get_last()['message']); + } } else { $a = (array) $interval; $this->description = \PHP_VERSION_ID >= 80200 && $a['from_string'] ? $a['date_string'] : 'DateInterval';