Improve FnType to add a body or block

Signed-off-by: David Arendsen <darendsen@gamepoint.com>
This commit is contained in:
David Arendsen 2023-03-08 21:20:20 +01:00
commit ec73c70706
4 changed files with 56 additions and 26 deletions

View file

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Tests\Functions;
use Arendsen\FluxQueryBuilder\Functions\AggregateWindow;
use Arendsen\FluxQueryBuilder\Type\FnType;
use PHPUnit\Framework\TestCase;
final class AggregateWindowFunctionTest extends TestCase
@ -20,18 +21,22 @@ final class AggregateWindowFunctionTest extends TestCase
public function testAllParameters()
{
$expression = new AggregateWindow('20s', 'mean', [
'period' => 'every',
'offset' => '0s',
'location' => 'location',
'column' => '_value',
'timeSrc' => '_stop',
'timeDst' => '_time',
'createEmpty' => false
]);
$expression = new AggregateWindow(
'20s',
FnType::params(['r'])->withBody('r._field == "test"'),
[
'period' => 'every',
'offset' => '0s',
'location' => 'location',
'column' => '_value',
'timeSrc' => '_stop',
'timeDst' => '_time',
'createEmpty' => false
]
);
$query = '|> aggregateWindow(every: 20s, period: every, offset: 0s, fn: mean, location: "location", ' .
'column: "_value", timeSrc: "_stop", timeDst: "_time", createEmpty: false) ';
$query = '|> aggregateWindow(every: 20s, period: every, offset: 0s, fn: (r) => r._field == "test",
location: "location", ' . 'column: "_value", timeSrc: "_stop", timeDst: "_time", createEmpty: false) ';
$this->assertEquals($query, $expression->__toString());
}