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
60
60
/**
61
61
* @dataProvider getInvalidIntervals
62
62
*/
63
- public function testInvalidInterval ($ interval )
63
+ public function testInvalidInterval ($ interval, $ expectedExceptionMessage )
64
64
{
65
65
$ this ->expectException (InvalidArgumentException::class);
66
+ $ this ->expectExceptionMessage ($ expectedExceptionMessage );
66
67
67
68
new PeriodicalTrigger ($ interval , $ now = new \DateTimeImmutable (), $ now ->modify ('1 day ' ));
68
69
}
69
70
70
71
public static function getInvalidIntervals (): iterable
71
72
{
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. ' ];
78
79
}
79
80
80
81
/**
Original file line number Diff line number Diff line change @@ -52,7 +52,11 @@ public function __construct(
52
52
$ i = $ interval ;
53
53
if (\is_string ($ interval )) {
54
54
$ 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
+ }
56
60
} else {
57
61
$ a = (array ) $ interval ;
58
62
$ 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