Add DateTime required param for Range functions

Signed-off-by: davidarendsen <davidarendsen@hey.com>
This commit is contained in:
davidarendsen 2022-08-12 21:25:03 +00:00
commit 95e71624d5
5 changed files with 33 additions and 51 deletions

View file

@ -10,40 +10,37 @@ final class RangeFunctionTest extends TestCase {
public function testOnlyStartOption()
{
$expression = new Range(['start' => '-360h']);
$expression = new Range(
new DateTime('2022-08-12 18:00:00')
);
$query = '|> range(start: -360h) ';
$query = '|> range(start: time(v: 2022-08-12T18:00:00Z)) ';
$this->assertEquals($query, $expression->__toString());
}
public function testWithStopOption()
{
$expression = new Range(['start' => '-360h', 'stop' => 'now()']);
$expression = new Range(
new DateTime('2022-08-12 18:00:00'),
new DateTime('2022-08-12 20:00:00')
);
$query = '|> range(start: -360h, stop: now()) ';
$query = '|> range(start: time(v: 2022-08-12T18:00:00Z), stop: time(v: 2022-08-12T20:00:00Z)) ';
$this->assertEquals($query, $expression->__toString());
}
public function testRangeInBetween()
{
$expression = new Range([
'start' => new DateTime('2022-08-12 17:31:00'),
'stop' => new DateTime('2022-08-12 18:31:00'),
]);
$expression = new Range(
new DateTime('2022-08-12 17:31:00'),
new DateTime('2022-08-12 18:31:00'),
);
$expected = '|> range(start: time(v: 2022-08-12T17:31:00Z), stop: time(v: 2022-08-12T18:31:00Z)) ';
$this->assertEquals($expected, $expression->__toString());
}
public function testThrowsExceptionWhenStartIsMissing()
{
$this->expectException(FunctionRequiredSettingMissingException::class);
$expression = new Range(['stop' => 'now()']);
$expression->__toString();
}
}