Add KeyValue expression
Signed-off-by: davidarendsen <davidarendsen@hey.com>
This commit is contained in:
parent
e0e69b4beb
commit
b2d1bd403c
7 changed files with 67 additions and 92 deletions
25
tests/Function/FilterFunctionTest.php
Normal file
25
tests/Function/FilterFunctionTest.php
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Expression\KeyValue;
|
||||
use Arendsen\FluxQueryBuilder\Function\Filter;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class FilterFunctionTest extends TestCase {
|
||||
|
||||
public function testSimpleFilter()
|
||||
{
|
||||
$expression = new Filter([
|
||||
KeyValue::set('_measurement', 'test_measurement')
|
||||
->and('_field', 'user')
|
||||
->or('_field', 'field2')
|
||||
->and('user', 'my_username'),
|
||||
]);
|
||||
|
||||
$query = '|> filter(fn: (r) => r._measurement == "test_measurement" and r._field == "user" or ' .
|
||||
'r._field == "field2" and r.user == "my_username") ';
|
||||
|
||||
$this->assertEquals($expression->__toString(), $query);
|
||||
}
|
||||
|
||||
}
|
||||
38
tests/Function/FromFunctionTest.php
Normal file
38
tests/Function/FromFunctionTest.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Function\From;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class FromFunctionTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @dataProvider somethingProvider
|
||||
*/
|
||||
public function testSomething($settings, $query)
|
||||
{
|
||||
$expression = new From($settings);
|
||||
|
||||
$this->assertEquals($expression->__toString(), $query);
|
||||
}
|
||||
|
||||
public function somethingProvider(): array
|
||||
{
|
||||
return [
|
||||
'from bucket' => [
|
||||
[
|
||||
'bucket' => 'test-bucket',
|
||||
],
|
||||
'from(bucket: "test-bucket") '
|
||||
],
|
||||
'from bucket and host' => [
|
||||
[
|
||||
'bucket' => 'test-bucket',
|
||||
'host' => 'test',
|
||||
],
|
||||
'from(bucket: "test-bucket", host: "test") '
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue