Skip to content

Commit

Permalink
Merge branch '6.4' into 7.1
Browse files Browse the repository at this point in the history
* 6.4:
  [FrameworkBundle] Fix wrong merge
  silence PHP warning when an invalid date interval format string is used
  • Loading branch information
fabpot committed Oct 14, 2024
2 parents 54b87a0 + e45354b commit 26d1092
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
15 changes: 8 additions & 7 deletions Tests/Trigger/PeriodicalTriggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'];
}

/**
Expand Down
6 changes: 5 additions & 1 deletion Trigger/PeriodicalTrigger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $a['from_string'] ? $a['date_string'] : 'DateInterval';
Expand Down

0 comments on commit 26d1092

Please sign in to comment.