File tree Expand file tree Collapse file tree 2 files changed +13
-8
lines changed
src/Symfony/Component/Scheduler Expand file tree Collapse file tree 2 files changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -60,21 +60,22 @@ public static function provideForConstructor(): iterable
6060 /**
6161 * @dataProvider getInvalidIntervals
6262 */
63- public function testInvalidInterval ($ interval )
63+ public function testInvalidInterval ($ interval, $ expectedExceptionMessage )
6464 {
6565 $ this ->expectException (InvalidArgumentException::class);
66+ $ this ->expectExceptionMessage ($ expectedExceptionMessage );
6667
6768 new PeriodicalTrigger ($ interval , $ now = new \DateTimeImmutable (), $ now ->modify ('1 day ' ));
6869 }
6970
7071 public static function getInvalidIntervals (): iterable
7172 {
72- yield ['wrong ' ];
73- yield ['3600.5 ' ];
74- yield ['-3600 ' ];
75- yield [-3600 ];
76- yield ['0 ' ];
77- yield [0 ];
73+ yield ['wrong ' , ' Unknown or bad format (wrong) at position 0 (w): The timezone could not be found in the database ' ];
74+ yield ['3600.5 ' , ' Unknown or bad format (3600.5) at position 5 (5): Unexpected character ' ];
75+ yield ['-3600 ' , ' Unknown or bad format (-3600) at position 3 (0): Unexpected character ' ];
76+ yield [-3600 , ' The "$interval" argument must be greater than zero. ' ];
77+ yield ['0 ' , ' The "$interval" argument must be greater than zero. ' ];
78+ yield [0 , ' The "$interval" argument must be greater than zero. ' ];
7879 }
7980
8081 /**
Original file line number Diff line number Diff line change @@ -52,7 +52,11 @@ public function __construct(
5252 $ i = $ interval ;
5353 if (\is_string ($ interval )) {
5454 $ this ->description = sprintf ('every %s ' , $ interval );
55- $ i = \DateInterval::createFromDateString ($ interval );
55+ $ i = @\DateInterval::createFromDateString ($ interval );
56+
57+ if (false === $ i ) {
58+ throw new InvalidArgumentException (sprintf ('Invalid interval "%s": ' , $ interval ).error_get_last ()['message ' ]);
59+ }
5660 } else {
5761 $ a = (array ) $ interval ;
5862 $ this ->description = \PHP_VERSION_ID >= 80200 && $ a ['from_string ' ] ? $ a ['date_string ' ] : 'DateInterval ' ;
You can’t perform that action at this time.
0 commit comments