|
27 | 27 | use WikibaseSolutions\CypherDSL\Assignment;
|
28 | 28 | use WikibaseSolutions\CypherDSL\Clauses\Clause;
|
29 | 29 | use WikibaseSolutions\CypherDSL\Clauses\MatchClause;
|
| 30 | +use WikibaseSolutions\CypherDSL\Clauses\UnionClause; |
30 | 31 | use WikibaseSolutions\CypherDSL\Exists;
|
31 | 32 | use WikibaseSolutions\CypherDSL\ExpressionList;
|
32 | 33 | use WikibaseSolutions\CypherDSL\Literals\Boolean;
|
@@ -1028,6 +1029,60 @@ public function testWikiExamples(): void
|
1028 | 1029 | $this->assertSame("((nineties.released >= 1990) AND (nineties IS NOT NULL))", $expression->toQuery());
|
1029 | 1030 | }
|
1030 | 1031 |
|
| 1032 | + public function testUnionQueryAll(): void |
| 1033 | + { |
| 1034 | + $nodeX = Query::node('X')->named('x'); |
| 1035 | + $nodeY = Query::node('Y')->named('y'); |
| 1036 | + |
| 1037 | + $query = Query::new()->match($nodeX)->returning($nodeX->getVariable()); |
| 1038 | + $right = Query::new()->match($nodeY)->returning($nodeY->getVariable()); |
| 1039 | + |
| 1040 | + $query = $query->union($right, true); |
| 1041 | + |
| 1042 | + $this->assertEquals('MATCH (x:X) RETURN x UNION ALL MATCH (y:Y) RETURN y', $query->toQuery()); |
| 1043 | + } |
| 1044 | + |
| 1045 | + public function testUnionQuery(): void |
| 1046 | + { |
| 1047 | + $nodeX = Query::node('X')->named('x'); |
| 1048 | + $nodeY = Query::node('Y')->named('y'); |
| 1049 | + |
| 1050 | + $query = Query::new()->match($nodeX)->returning($nodeX->getVariable()); |
| 1051 | + $right = Query::new()->match($nodeY)->returning($nodeY->getVariable()); |
| 1052 | + |
| 1053 | + $query = $query->union($right, false); |
| 1054 | + |
| 1055 | + $this->assertEquals('MATCH (x:X) RETURN x UNION MATCH (y:Y) RETURN y', $query->toQuery()); |
| 1056 | + } |
| 1057 | + |
| 1058 | + public function testUnionDecorator(): void |
| 1059 | + { |
| 1060 | + $nodeX = Query::node('X')->named('x'); |
| 1061 | + |
| 1062 | + $query = Query::new()->match($nodeX)->returning($nodeX->getVariable()); |
| 1063 | + |
| 1064 | + $query = $query->union(function (Query $query) { |
| 1065 | + $nodeY = Query::node('Y')->named('y'); |
| 1066 | + $query->match($nodeY)->returning($nodeY->getVariable()); |
| 1067 | + }); |
| 1068 | + |
| 1069 | + $this->assertEquals('MATCH (x:X) RETURN x UNION MATCH (y:Y) RETURN y', $query->toQuery()); |
| 1070 | + } |
| 1071 | + |
| 1072 | + public function testUnionDecoratorAll(): void |
| 1073 | + { |
| 1074 | + $nodeX = Query::node('X')->named('x'); |
| 1075 | + |
| 1076 | + $query = Query::new()->match($nodeX)->returning($nodeX->getVariable()); |
| 1077 | + |
| 1078 | + $query = $query->union(function (Query $query) { |
| 1079 | + $nodeY = Query::node('Y')->named('y'); |
| 1080 | + $query->match($nodeY)->returning($nodeY->getVariable()); |
| 1081 | + }, true); |
| 1082 | + |
| 1083 | + $this->assertEquals('MATCH (x:X) RETURN x UNION ALL MATCH (y:Y) RETURN y', $query->toQuery()); |
| 1084 | + } |
| 1085 | + |
1031 | 1086 | public function testAutomaticIdentifierGeneration(): void
|
1032 | 1087 | {
|
1033 | 1088 | $node = Query::node();
|
|
0 commit comments