File tree Expand file tree Collapse file tree 2 files changed +48
-12
lines changed Expand file tree Collapse file tree 2 files changed +48
-12
lines changed Original file line number Diff line number Diff line change @@ -14,37 +14,43 @@ class CallClause extends Clause
14
14
/**
15
15
* @var Query The query to call.
16
16
*/
17
- private Query $ query ;
17
+ private Query $ subQuery ;
18
18
19
19
/**
20
- * @param Query $query The query to call.
20
+ * @param Query $subQuery The query to call.
21
21
*/
22
- public function __construct (Query $ query )
22
+ public function __construct (Query $ subQuery )
23
23
{
24
- $ this ->query = $ query ;
25
- }
26
-
27
- public function toQuery (): string
28
- {
29
- return sprintf ('CALL { %s } ' , $ this ->getSubject ());
24
+ $ this ->subQuery = $ subQuery ;
30
25
}
31
26
32
27
/**
33
28
* Returns the query that is being called.
34
29
*
35
30
* @return Query
36
31
*/
37
- public function getQuery (): Query
32
+ public function getSubQuery (): Query
33
+ {
34
+ return $ this ->subQuery ;
35
+ }
36
+
37
+ public function toQuery (): string
38
38
{
39
- return $ this ->query ;
39
+ $ subQuery = trim ($ this ->subQuery ->toQuery ());
40
+
41
+ if ($ subQuery === '' ) {
42
+ return '' ;
43
+ }
44
+
45
+ return sprintf ('CALL { %s } ' , $ subQuery );
40
46
}
41
47
42
48
/**
43
49
* @inheritDoc
44
50
*/
45
51
protected function getSubject (): string
46
52
{
47
- return $ this ->query ->toQuery ();
53
+ return ' { ' . $ this ->subQuery ->toQuery () . ' } ' ;
48
54
}
49
55
50
56
/**
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace WikibaseSolutions \CypherDSL \Tests \Unit \Clauses ;
4
+
5
+ use PHPUnit \Framework \TestCase ;
6
+ use WikibaseSolutions \CypherDSL \Clauses \CallClause ;
7
+ use WikibaseSolutions \CypherDSL \Query ;
8
+
9
+ class CallClauseTest extends TestCase
10
+ {
11
+ public function testCallClauseEmpty (): void
12
+ {
13
+ $ query = Query::new ();
14
+
15
+ $ clause = new CallClause ($ query );
16
+
17
+ $ this ->assertEquals ('' , $ clause ->toQuery ());
18
+ $ this ->assertEquals (Query::new (), $ clause ->getSubQuery ());
19
+ }
20
+
21
+ public function testCallClauseFilled (): void
22
+ {
23
+ $ query = Query::new ()->match (Query::node ('X ' )->named ('x ' ))->returning (Query::rawExpression ('* ' ));
24
+
25
+ $ clause = new CallClause ($ query );
26
+
27
+ $ this ->assertEquals ('CALL { MATCH (x:X) RETURN * } ' , $ clause ->toQuery ());
28
+ $ this ->assertEquals ($ query , $ clause ->getSubQuery ());
29
+ }
30
+ }
You can’t perform that action at this time.
0 commit comments