Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5720bac

Browse filesBrowse files
committed
bug #58550 [Scheduler] silence PHP warning when an invalid date interval format string is used (xabbuh)
This PR was merged into the 6.4 branch. Discussion ---------- [Scheduler] silence PHP warning when an invalid date interval format string is used | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | | License | MIT Commits ------- dc43906 silence PHP warning when an invalid date interval format string is used
2 parents 9adf252 + dc43906 commit 5720bac
Copy full SHA for 5720bac

File tree

2 files changed

+13
-8
lines changed
Filter options

2 files changed

+13
-8
lines changed

‎src/Symfony/Component/Scheduler/Tests/Trigger/PeriodicalTriggerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Scheduler/Tests/Trigger/PeriodicalTriggerTest.php
+8-7Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff 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
/**

‎src/Symfony/Component/Scheduler/Trigger/PeriodicalTrigger.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Scheduler/Trigger/PeriodicalTrigger.php
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff 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';

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.