Marks fork as 2.0.0.
This commit is contained in:
parent
d93a6b5c09
commit
8d8de4a2b0
81 changed files with 1921 additions and 3954 deletions
|
|
@ -1,43 +1,40 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\AggregateWindow;
|
||||
use Arendsen\FluxQueryBuilder\Type\FnType;
|
||||
use Hosterra\FluxBuilder\Functions\AggregateWindow;
|
||||
use Hosterra\FluxBuilder\Type\FnType;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class AggregateWindowFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleWindow()
|
||||
{
|
||||
$expression = new AggregateWindow('20s', 'mean');
|
||||
final class AggregateWindowFunctionTest extends TestCase {
|
||||
public function testSimpleWindow() {
|
||||
$expression = new AggregateWindow( '20s', 'mean' );
|
||||
|
||||
$query = '|> aggregateWindow(every: 20s, fn: mean) ';
|
||||
$query = '|> aggregateWindow(every: 20s, fn: mean) ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
|
||||
public function testAllParameters()
|
||||
{
|
||||
$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
|
||||
]
|
||||
);
|
||||
public function testAllParameters() {
|
||||
$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: (r) => r._field == "test", ' .
|
||||
'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());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,26 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Count;
|
||||
use Hosterra\FluxBuilder\Functions\Count;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class CountFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleCount()
|
||||
{
|
||||
$expression = new Count();
|
||||
final class CountFunctionTest extends TestCase {
|
||||
public function testSimpleCount() {
|
||||
$expression = new Count();
|
||||
|
||||
$query = '|> count() ';
|
||||
$query = '|> count() ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
|
||||
public function testCountWithColumn()
|
||||
{
|
||||
$expression = new Count('_value');
|
||||
public function testCountWithColumn() {
|
||||
$expression = new Count( '_value' );
|
||||
|
||||
$query = '|> count(column: "_value") ';
|
||||
$query = '|> count(column: "_value") ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,18 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Duplicate;
|
||||
use Hosterra\FluxBuilder\Functions\Duplicate;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class DuplicateFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleDuplicate()
|
||||
{
|
||||
$expression = new Duplicate('tag', 'tag_dup');
|
||||
final class DuplicateFunctionTest extends TestCase {
|
||||
public function testSimpleDuplicate() {
|
||||
$expression = new Duplicate( 'tag', 'tag_dup' );
|
||||
|
||||
$query = '|> duplicate(column: "tag", as: "tag_dup") ';
|
||||
$query = '|> duplicate(column: "tag", as: "tag_dup") ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,48 +1,33 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Expression\KeyValue;
|
||||
use Arendsen\FluxQueryBuilder\Expression\KeyFilter;
|
||||
use Arendsen\FluxQueryBuilder\Functions\Filter;
|
||||
|
||||
use Hosterra\FluxBuilder\Expression\KeyFilter;
|
||||
use Hosterra\FluxBuilder\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'));
|
||||
final class FilterFunctionTest extends TestCase {
|
||||
|
||||
$query = '|> filter(fn: (r) => r._measurement == "test_measurement" and r._field == "user" or ' .
|
||||
'r._field == "field2" and r.user == "my_username") ';
|
||||
public function testFieldFilter() {
|
||||
$expression = new Filter( [ 'user', 'field2', 'field3' ] );
|
||||
|
||||
$this->assertEquals($expression->__toString(), $query);
|
||||
}
|
||||
$query = '|> filter(fn: (r) => r._field == "user" or r._field == "field2" or r._field == "field3") ';
|
||||
|
||||
public function testFieldFilter()
|
||||
{
|
||||
$expression = new Filter(['user', 'field2', 'field3']);
|
||||
$this->assertEquals( $expression->__toString(), $query );
|
||||
}
|
||||
|
||||
$query = '|> filter(fn: (r) => r._field == "user" or r._field == "field2" or r._field == "field3") ';
|
||||
public function testKeyFilter() {
|
||||
$expression = new Filter( KeyFilter::setEqualTo( '_measurement', 'test_measurement' )
|
||||
->andEqualTo( '_field', 'user' )
|
||||
->orEqualTo( '_field', 'field2' )
|
||||
->andEqualTo( 'user', 'my_username' ) );
|
||||
|
||||
$this->assertEquals($expression->__toString(), $query);
|
||||
}
|
||||
$query = '|> filter(fn: (r) => r._measurement == "test_measurement" and r._field == "user" or ' .
|
||||
'r._field == "field2" and r.user == "my_username") ';
|
||||
|
||||
public function testKeyFilter()
|
||||
{
|
||||
$expression = new Filter(KeyFilter::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);
|
||||
}
|
||||
$this->assertEquals( $expression->__toString(), $query );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,26 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\First;
|
||||
use Hosterra\FluxBuilder\Functions\First;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class FirstFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleFirst()
|
||||
{
|
||||
$expression = new First();
|
||||
final class FirstFunctionTest extends TestCase {
|
||||
public function testSimpleFirst() {
|
||||
$expression = new First();
|
||||
|
||||
$query = '|> first() ';
|
||||
$query = '|> first() ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
|
||||
public function testFirstWithColumn()
|
||||
{
|
||||
$expression = new First('something');
|
||||
public function testFirstWithColumn() {
|
||||
$expression = new First( 'something' );
|
||||
|
||||
$query = '|> first(column: "something") ';
|
||||
$query = '|> first(column: "something") ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,40 +1,37 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\From;
|
||||
use Hosterra\FluxBuilder\Functions\From;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class FromFunctionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider somethingProvider
|
||||
*/
|
||||
public function testSomething($settings, $query)
|
||||
{
|
||||
$expression = new From($settings);
|
||||
final class FromFunctionTest extends TestCase {
|
||||
/**
|
||||
* @dataProvider somethingProvider
|
||||
*/
|
||||
public function testSomething( $settings, $query ) {
|
||||
$expression = new From( $settings );
|
||||
|
||||
$this->assertEquals($expression->__toString(), $query);
|
||||
}
|
||||
$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") '
|
||||
],
|
||||
];
|
||||
}
|
||||
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") '
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,18 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Group;
|
||||
use Hosterra\FluxBuilder\Functions\Group;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class GroupFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleGroup()
|
||||
{
|
||||
$expression = new Group(['foo', 'bar'], 'by');
|
||||
final class GroupFunctionTest extends TestCase {
|
||||
public function testSimpleGroup() {
|
||||
$expression = new Group( [ 'foo', 'bar' ], 'by' );
|
||||
|
||||
$query = '|> group(columns: ["foo", "bar"], mode: "by") ';
|
||||
$query = '|> group(columns: ["foo", "bar"], mode: "by") ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,26 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Last;
|
||||
use Hosterra\FluxBuilder\Functions\Last;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class LastFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleLast()
|
||||
{
|
||||
$expression = new Last();
|
||||
final class LastFunctionTest extends TestCase {
|
||||
public function testSimpleLast() {
|
||||
$expression = new Last();
|
||||
|
||||
$query = '|> last(column: "_value") ';
|
||||
$query = '|> last(column: "_value") ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
|
||||
public function testLastWithValue()
|
||||
{
|
||||
$expression = new Last('something');
|
||||
public function testLastWithValue() {
|
||||
$expression = new Last( 'something' );
|
||||
|
||||
$query = '|> last(column: "something") ';
|
||||
$query = '|> last(column: "something") ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,26 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Limit;
|
||||
use Hosterra\FluxBuilder\Functions\Limit;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class LimitFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleLimit()
|
||||
{
|
||||
$expression = new Limit(1);
|
||||
final class LimitFunctionTest extends TestCase {
|
||||
public function testSimpleLimit() {
|
||||
$expression = new Limit( 1 );
|
||||
|
||||
$query = '|> limit(n: 1, offset: 0) ';
|
||||
$query = '|> limit(n: 1, offset: 0) ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
|
||||
public function testLimitWithOffset()
|
||||
{
|
||||
$expression = new Limit(10, 2);
|
||||
public function testLimitWithOffset() {
|
||||
$expression = new Limit( 10, 2 );
|
||||
|
||||
$query = '|> limit(n: 10, offset: 2) ';
|
||||
$query = '|> limit(n: 10, offset: 2) ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,47 +1,43 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Map;
|
||||
use Arendsen\FluxQueryBuilder\Expression\Map as MapExpression;
|
||||
use Arendsen\FluxQueryBuilder\Expression\Selection as SelectionExpression;
|
||||
use Hosterra\FluxBuilder\Functions\Map;
|
||||
use Hosterra\FluxBuilder\Expression\Map as MapExpression;
|
||||
use Hosterra\FluxBuilder\Expression\Selection as SelectionExpression;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class MapFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleMap()
|
||||
{
|
||||
$expression = new Map('r with name: r.user');
|
||||
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 })) ';
|
||||
$query = '|> map(fn: (r) => ({ r with name: r.user })) ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
|
||||
public function testWithMapObject()
|
||||
{
|
||||
$expression = new Map(MapExpression::with('name', 'r.user'));
|
||||
public function testWithMapObject() {
|
||||
$expression = new Map( MapExpression::with( 'name', 'r.user' ) );
|
||||
|
||||
$query = '|> map(fn: (r) => ({ r with name: r.user })) ';
|
||||
$query = '|> map(fn: (r) => ({ r with name: r.user })) ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
|
||||
public function testRecordMapObject()
|
||||
{
|
||||
$expression = new Map(MapExpression::columns([
|
||||
'time' => 'r._time',
|
||||
'source' => 'r.tag',
|
||||
'alert' => SelectionExpression::if('r._value > 10')->then(true)->else(false)->__toString(),
|
||||
'test' => SelectionExpression::if('r._value > 10')->then('yes')->else('no')->__toString()
|
||||
])->__toString());
|
||||
public function testRecordMapObject() {
|
||||
$expression = new Map( MapExpression::columns( [
|
||||
'time' => 'r._time',
|
||||
'source' => 'r.tag',
|
||||
'alert' => SelectionExpression::if( 'r._value > 10' )->then( true )->else( false )->__toString(),
|
||||
'test' => SelectionExpression::if( 'r._value > 10' )->then( 'yes' )->else( 'no' )->__toString()
|
||||
] )->__toString() );
|
||||
|
||||
$query = '|> map(fn: (r) => ({ {time: r._time, source: r.tag, ' .
|
||||
'alert: if r._value > 10 then true else false, ' .
|
||||
'test: if r._value > 10 then "yes" else "no"} })) ';
|
||||
$query = '|> map(fn: (r) => ({ {time: r._time, source: r.tag, ' .
|
||||
'alert: if r._value > 10 then true else false, ' .
|
||||
'test: if r._value > 10 then "yes" else "no"} })) ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,26 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Max;
|
||||
use Hosterra\FluxBuilder\Functions\Max;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class MaxFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleMax()
|
||||
{
|
||||
$expression = new Max();
|
||||
final class MaxFunctionTest extends TestCase {
|
||||
public function testSimpleMax() {
|
||||
$expression = new Max();
|
||||
|
||||
$query = '|> max() ';
|
||||
$query = '|> max() ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
|
||||
public function testMaxWithColumn()
|
||||
{
|
||||
$expression = new Max('something');
|
||||
public function testMaxWithColumn() {
|
||||
$expression = new Max( 'something' );
|
||||
|
||||
$query = '|> max(column: "something") ';
|
||||
$query = '|> max(column: "something") ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,26 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Mean;
|
||||
use Hosterra\FluxBuilder\Functions\Mean;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class MeanFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleMean()
|
||||
{
|
||||
$expression = new Mean();
|
||||
final class MeanFunctionTest extends TestCase {
|
||||
public function testSimpleMean() {
|
||||
$expression = new Mean();
|
||||
|
||||
$query = '|> mean() ';
|
||||
$query = '|> mean() ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
|
||||
public function testWithParameterColumn()
|
||||
{
|
||||
$expression = new Mean('test');
|
||||
public function testWithParameterColumn() {
|
||||
$expression = new Mean( 'test' );
|
||||
|
||||
$query = '|> mean(column: "test") ';
|
||||
$query = '|> mean(column: "test") ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,26 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Min;
|
||||
use Hosterra\FluxBuilder\Functions\Min;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class MinFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleMin()
|
||||
{
|
||||
$expression = new Min();
|
||||
final class MinFunctionTest extends TestCase {
|
||||
public function testSimpleMin() {
|
||||
$expression = new Min();
|
||||
|
||||
$query = '|> min() ';
|
||||
$query = '|> min() ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
|
||||
public function testMinWithColumn()
|
||||
{
|
||||
$expression = new Min('something');
|
||||
public function testMinWithColumn() {
|
||||
$expression = new Min( 'something' );
|
||||
|
||||
$query = '|> min(column: "something") ';
|
||||
$query = '|> min(column: "something") ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,47 +1,43 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use DateTime;
|
||||
use Arendsen\FluxQueryBuilder\Functions\Range;
|
||||
use Hosterra\FluxBuilder\Functions\Range;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class RangeFunctionTest extends TestCase
|
||||
{
|
||||
public function testOnlyStartOption()
|
||||
{
|
||||
$expression = new Range(
|
||||
new DateTime('2022-08-12 18:00:00')
|
||||
);
|
||||
final class RangeFunctionTest extends TestCase {
|
||||
public function testOnlyStartOption() {
|
||||
$expression = new Range(
|
||||
new DateTime( '2022-08-12 18:00:00' )
|
||||
);
|
||||
|
||||
$query = '|> range(start: time(v: 2022-08-12T18:00:00Z)) ';
|
||||
$query = '|> range(start: time(v: 2022-08-12T18:00:00Z)) ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
|
||||
public function testWithStopOption()
|
||||
{
|
||||
$expression = new Range(
|
||||
new DateTime('2022-08-12 18:00:00'),
|
||||
new DateTime('2022-08-12 20:00:00')
|
||||
);
|
||||
public function testWithStopOption() {
|
||||
$expression = new Range(
|
||||
new DateTime( '2022-08-12 18:00:00' ),
|
||||
new DateTime( '2022-08-12 20:00:00' )
|
||||
);
|
||||
|
||||
$query = '|> range(start: time(v: 2022-08-12T18:00:00Z), stop: time(v: 2022-08-12T20:00:00Z)) ';
|
||||
$query = '|> range(start: time(v: 2022-08-12T18:00:00Z), stop: time(v: 2022-08-12T20:00:00Z)) ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
|
||||
public function testRangeInBetween()
|
||||
{
|
||||
$expression = new Range(
|
||||
new DateTime('2022-08-12 17:31:00'),
|
||||
new DateTime('2022-08-12 18:31:00')
|
||||
);
|
||||
public function testRangeInBetween() {
|
||||
$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)) ';
|
||||
$expected = '|> range(start: time(v: 2022-08-12T17:31:00Z), stop: time(v: 2022-08-12T18:31:00Z)) ';
|
||||
|
||||
$this->assertEquals($expected, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $expected, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,19 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Reduce;
|
||||
use Arendsen\FluxQueryBuilder\Type\MathType;
|
||||
use Hosterra\FluxBuilder\Functions\Reduce;
|
||||
use Hosterra\FluxBuilder\Type\MathType;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class ReduceFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleReduce()
|
||||
{
|
||||
$expression = new Reduce(['sum' => new MathType('r._value + accumulator.sum')], ['sum' => 0]);
|
||||
final class ReduceFunctionTest extends TestCase {
|
||||
public function testSimpleReduce() {
|
||||
$expression = new Reduce( [ 'sum' => new MathType( 'r._value + accumulator.sum' ) ], [ 'sum' => 0 ] );
|
||||
|
||||
$query = '|> reduce(fn: (r, accumulator) => ({sum: r._value + accumulator.sum}), identity: {sum: 0}) ';
|
||||
$query = '|> reduce(fn: (r, accumulator) => ({sum: r._value + accumulator.sum}), identity: {sum: 0}) ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,18 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Sort;
|
||||
use Hosterra\FluxBuilder\Functions\Sort;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class SortFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleSort()
|
||||
{
|
||||
$expression = new Sort(['foo', 'bar'], true);
|
||||
final class SortFunctionTest extends TestCase {
|
||||
public function testSimpleSort() {
|
||||
$expression = new Sort( [ 'foo', 'bar' ], true );
|
||||
|
||||
$query = '|> sort(columns: ["foo", "bar"], desc: true) ';
|
||||
$query = '|> sort(columns: ["foo", "bar"], desc: true) ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,18 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Sum;
|
||||
use Hosterra\FluxBuilder\Functions\Sum;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class SumFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleSum()
|
||||
{
|
||||
$expression = new Sum('_value');
|
||||
final class SumFunctionTest extends TestCase {
|
||||
public function testSimpleSum() {
|
||||
$expression = new Sum( '_value' );
|
||||
|
||||
$query = '|> sum(column: "_value") ';
|
||||
$query = '|> sum(column: "_value") ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,26 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Unique;
|
||||
use Hosterra\FluxBuilder\Functions\Unique;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class UniqueunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleUnique()
|
||||
{
|
||||
$expression = new Unique();
|
||||
final class UniqueunctionTest extends TestCase {
|
||||
public function testSimpleUnique() {
|
||||
$expression = new Unique();
|
||||
|
||||
$query = '|> unique() ';
|
||||
$query = '|> unique() ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
|
||||
public function testUniqueWithColumn()
|
||||
{
|
||||
$expression = new Unique('something');
|
||||
public function testUniqueWithColumn() {
|
||||
$expression = new Unique( 'something' );
|
||||
|
||||
$query = '|> unique(column: "something") ';
|
||||
$query = '|> unique(column: "something") ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,38 +1,35 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Window;
|
||||
use Hosterra\FluxBuilder\Functions\Window;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class WindowFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleWindow()
|
||||
{
|
||||
$expression = new Window('20s');
|
||||
final class WindowFunctionTest extends TestCase {
|
||||
public function testSimpleWindow() {
|
||||
$expression = new Window( '20s' );
|
||||
|
||||
$query = '|> window(every: 20s) ';
|
||||
$query = '|> window(every: 20s) ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
|
||||
public function testAllParameters()
|
||||
{
|
||||
$expression = new Window('20s', [
|
||||
'period' => 'every',
|
||||
'offset' => '0s',
|
||||
'location' => 'location',
|
||||
'timeColumn' => '_time',
|
||||
'startColumn' => '_start',
|
||||
'stopColumn' => '_stop',
|
||||
'createEmpty' => true
|
||||
]);
|
||||
public function testAllParameters() {
|
||||
$expression = new Window( '20s', [
|
||||
'period' => 'every',
|
||||
'offset' => '0s',
|
||||
'location' => 'location',
|
||||
'timeColumn' => '_time',
|
||||
'startColumn' => '_start',
|
||||
'stopColumn' => '_stop',
|
||||
'createEmpty' => true
|
||||
] );
|
||||
|
||||
$query = '|> window(every: 20s, period: every, offset: 0s, location: "location", ' .
|
||||
'timeColumn: "_time", startColumn: "_start", stopColumn: "_stop", createEmpty: true) ';
|
||||
$query = '|> window(every: 20s, period: every, offset: 0s, location: "location", ' .
|
||||
'timeColumn: "_time", startColumn: "_start", stopColumn: "_stop", createEmpty: true) ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
editor.link_modal.header
Reference in a new issue