Skip to content

Commit 5e0a37a

Browse files
- removed duplicate !array check in for clause
- fixed array of predicates falsely being recognized as a single predicate instead of a group. - SupportCommandsTest correctly covers bindArrayValues - added tests for unbounded and time based aggregation window queries.
1 parent af9ee29 commit 5e0a37a

File tree

6 files changed

+58
-8
lines changed

6 files changed

+58
-8
lines changed

src/AQL/HasQueryClauses.php

-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use LaravelFreelancerNL\FluentAQL\Clauses\WithCountClause;
2020
use LaravelFreelancerNL\FluentAQL\Expressions\Expression;
2121
use LaravelFreelancerNL\FluentAQL\QueryBuilder;
22-
use phpDocumentor\Reflection\Types\ArrayKey;
2322

2423
/**
2524
* Trait hasQueryClauses
@@ -192,7 +191,6 @@ public function aggregate(
192191
* @link https://www.arangodb.com/docs/stable/aql/operations-sort.html
193192
*
194193
* @param mixed ...$references
195-
* @return QueryBuilder
196194
*/
197195
public function sort(...$references): self
198196
{

src/Clauses/ForClause.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,15 @@ class ForClause extends Clause
2121
protected array|Expression|ExpressionInterface|QueryBuilder|string|null $in;
2222

2323
/**
24-
* @param array<string|Expression>|string|Expression $variables
24+
* @param array<string|Expression> $variables
2525
* @param array<mixed>|string|QueryBuilder|Expression|null $in
2626
*/
2727
public function __construct(
28-
array|string|Expression $variables,
28+
array $variables,
2929
array|string|QueryBuilder|Expression $in = null
3030
) {
3131
parent::__construct();
3232

33-
if (!is_array($variables)) {
34-
$variables = [$variables];
35-
}
3633
$this->variables = $variables;
3734

3835
$this->in = $in;

src/Traits/ValidatesPredicates.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ public function isPredicate(mixed $value): bool
1414
return true;
1515
}
1616

17-
if (is_array($value) && isset($value[0]) && ! is_array($value[0])) {
17+
if (
18+
is_array($value)
19+
&& isset($value[0])
20+
&& ! is_array($value[0])
21+
&& ! $value[0] instanceof PredicateExpression
22+
) {
1823
return true;
1924
}
2025

tests/Unit/AQL/QueryClausesTest.php

+25
Original file line numberDiff line numberDiff line change
@@ -439,4 +439,29 @@ public function testWindowClauseWithRange()
439439
$result->query
440440
);
441441
}
442+
443+
public function testWindowClauseUnbounded()
444+
{
445+
$result = (new QueryBuilder())
446+
->for('t', 'observations')
447+
->window(['preceding' => 'unbounded', 'following' => 10], 't.time')
448+
->get();
449+
450+
self::assertEquals(
451+
'FOR t IN observations WINDOW t.time WITH {"preceding":"unbounded","following":10}',
452+
$result->query
453+
);
454+
}
455+
public function testWindowClauseDurationBasedAggregation()
456+
{
457+
$qb = new QueryBuilder();
458+
$qb->for('t', 'observations')
459+
->window(['preceding' => 'PT30M'], $qb->dateTimestamp('t.time'))
460+
->get();
461+
462+
self::assertEquals(
463+
'FOR t IN observations WINDOW DATE_TIMESTAMP(t.time) WITH {"preceding":"PT30M"}',
464+
$qb->get()->query
465+
);
466+
}
442467
}

tests/Unit/AQL/SupportCommandsTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use LaravelFreelancerNL\FluentAQL\Tests\TestCase;
77

88
/**
9+
* @covers \LaravelFreelancerNL\FluentAQL\QueryBuilder
910
* @covers \LaravelFreelancerNL\FluentAQL\AQL\HasSupportCommands
1011
* @covers \LaravelFreelancerNL\FluentAQL\Clauses\RawClause
1112
*/

tests/Unit/Expressions/PredicateExpressionTest.php

+24
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,28 @@ public function testPredicateWithoutRightOperand()
6262

6363
self::assertEquals('x == null', $result);
6464
}
65+
66+
public function testGroupOfPredicateExpressions()
67+
{
68+
$qb = new QueryBuilder();
69+
$predicate1 = new PredicateExpression(
70+
(new LiteralExpression('u.name')),
71+
'==',
72+
'Cookie Monster'
73+
);
74+
$predicate2 = new PredicateExpression(
75+
(new LiteralExpression('u.age')),
76+
'==',
77+
27
78+
);
79+
80+
$result = $qb->for('u', 'users')
81+
->filter([$predicate1, $predicate2])
82+
->return('u');
83+
84+
self::assertEquals(
85+
'FOR u IN users FILTER u.name == @' . $qb->getQueryId() . '_1 AND u.age == 27 RETURN u',
86+
$result->get()->query
87+
);
88+
}
6589
}

0 commit comments

Comments
 (0)