Rename namespace Function keyword to Functions to prevent errors

Signed-off-by: davidarendsen <davidarendsen@hey.com>
This commit is contained in:
davidarendsen 2022-08-12 12:37:30 +00:00
commit 79edee7400
19 changed files with 31 additions and 31 deletions

View file

@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
use Arendsen\FluxQueryBuilder\Expression\KeyValue;
use Arendsen\FluxQueryBuilder\Functions\Filter;
use PHPUnit\Framework\TestCase;
final class FilterFunctionTest extends TestCase {
public function testSimpleFilter()
{
$expression = new Filter(KeyValue::setEqualTo('_measurement', 'test_measurement')
->andEqualTo('_field', 'user')
->orEqualTo('_field', 'field2')
->andEqualTo('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);
}
}

View file

@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
use Arendsen\FluxQueryBuilder\Functions\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") '
],
];
}
}

View file

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
use Arendsen\FluxQueryBuilder\Functions\Group;
use PHPUnit\Framework\TestCase;
final class GroupFunctionTest extends TestCase {
public function testSimpleGroup()
{
$expression = new Group(['foo', 'bar'], 'by');
$query = '|> group(columns: ["foo", "bar"], mode: "by") ';
$this->assertEquals($query, $expression->__toString());
}
}

View file

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
use Arendsen\FluxQueryBuilder\Functions\Limit;
use PHPUnit\Framework\TestCase;
final class LimitFunctionTest extends TestCase {
public function testSimpleLimit()
{
$expression = new Limit(1);
$query = '|> limit(n:1) ';
$this->assertEquals($query, $expression->__toString());
}
}

View file

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
use Arendsen\FluxQueryBuilder\Functions\Map;
use PHPUnit\Framework\TestCase;
final class MapFunctionTest extends TestCase {
public function testSimpleMap()
{
$expression = new Map('r with name: r.user');
$query = '|> map(fn: (r) => ({ r with name: r.user })) ';
$this->assertEquals($query, $expression->__toString());
}
}

View file

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
use Arendsen\FluxQueryBuilder\Functions\Reduce;
use PHPUnit\Framework\TestCase;
final class ReduceFunctionTest extends TestCase {
public function testSimpleReduce()
{
$expression = new Reduce(['sum' => 'r._value + accumulator.sum'], ['sum' => 0]);
$query = '|> reduce(fn: (r, accumulator) => ({sum: r._value + accumulator.sum}), identity: {sum: 0}) ';
$this->assertEquals($query, $expression->__toString());
}
}

View file

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
use Arendsen\FluxQueryBuilder\Functions\Sort;
use PHPUnit\Framework\TestCase;
final class SortFunctionTest extends TestCase {
public function testSimpleSort()
{
$expression = new Sort(['foo', 'bar'], true);
$query = '|> sort(columns: ["foo", "bar"], desc: true) ';
$this->assertEquals($query, $expression->__toString());
}
}