Skip to content

Commit bdd133a

Browse files
committed
added test for subquery in query
1 parent 57faa38 commit bdd133a

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/Query.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
namespace WikibaseSolutions\CypherDSL;
2323

24+
use Closure;
2425
use WikibaseSolutions\CypherDSL\Clauses\CallClause;
2526
use WikibaseSolutions\CypherDSL\Clauses\CallProcedureClause;
2627
use WikibaseSolutions\CypherDSL\Clauses\Clause;
@@ -56,7 +57,6 @@
5657
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\NodeType;
5758
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\PathType;
5859
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\StructuralType;
59-
use function call_user_func;
6060

6161
/**
6262
* Builder class for building complex Cypher queries.
@@ -648,8 +648,6 @@ public function callProcedure(string $procedure, array $arguments = [], array $y
648648
*/
649649
public function call($decorator): self
650650
{
651-
self::assertClass('decorator', 'callable', $decorator);
652-
653651
$subQuery = self::new();
654652

655653
$decorator($subQuery);

tests/Unit/QueryTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,20 @@ public function testAutomaticIdentifierGeneration(): void
10481048
$this->assertInstanceOf(Variable::class, $node->getName());
10491049
}
10501050

1051+
public function testCall(): void
1052+
{
1053+
$node = Query::node('X')->named('y');
1054+
$query = Query::new()->match($node)
1055+
->call(function (Query $subQuery) use ($node) {
1056+
$subQuery->with($node->getVariable())
1057+
->where($node->property('z')->equals(Query::literal('foo'), false))
1058+
->returning($node->property('z')->alias('foo'));
1059+
})
1060+
->returning(Query::variable('foo'));
1061+
1062+
$this->assertEquals("MATCH (y:X) CALL { WITH y WHERE y.z = 'foo' RETURN y.z AS foo } RETURN foo", $query->toQuery());
1063+
}
1064+
10511065
public function provideLiteralData(): array
10521066
{
10531067
return [

0 commit comments

Comments
 (0)