@@ -92,6 +92,13 @@ public function testVariable()
9292 $ this ->assertInstanceOf (Variable::class, Query::variable ("foo " ));
9393 }
9494
95+ public function testVariableEmpty ()
96+ {
97+ $ this ->assertInstanceOf (Variable::class, Query::variable ());
98+
99+ $ this ->assertMatchesRegularExpression ('/[0-9a-f]+/ ' , Query::variable ()->toQuery ());
100+ }
101+
95102 public function testParameter ()
96103 {
97104 $ this ->assertInstanceOf (Parameter::class, Query::parameter ("foo " ));
@@ -228,6 +235,22 @@ public function testReturning()
228235 $ this ->assertSame ("RETURN (m:Movie) AS n " , $ statement );
229236 }
230237
238+ public function testReturningWithNode ()
239+ {
240+ $ node = Query::node ("m " );
241+
242+ $ statement = (new Query ())->returning ($ node )->build ();
243+
244+ $ this ->assertMatchesRegularExpression ("/(RETURN [0-9a-f]+)/ " , $ statement );
245+
246+ $ node = Query::node ("m " );
247+ $ node ->named ('example ' );
248+
249+ $ statement = (new Query ())->returning ($ node )->build ();
250+
251+ $ this ->assertSame ('RETURN example ' , $ statement );
252+ }
253+
231254 public function testCreate ()
232255 {
233256 $ m = $ this ->getQueryConvertableMock (PathType::class, "(m:Movie)->(b) " );
@@ -379,6 +402,22 @@ public function testWith()
379402 $ this ->assertSame ("WITH a < b AS foobar " , $ statement );
380403 }
381404
405+ public function testWithWithNode ()
406+ {
407+ $ node = Query::node ('m ' );
408+
409+ $ statement = (new Query ())->with ($ node )->build ();
410+
411+ $ this ->assertMatchesRegularExpression ("/(WITH [0-9a-f]+)/ " , $ statement );
412+
413+ $ node = Query::node ("m " );
414+ $ node ->named ('example ' );
415+
416+ $ statement = (new Query ())->with ($ node )->build ();
417+
418+ $ this ->assertSame ('WITH example ' , $ statement );
419+ }
420+
382421 public function testCallProcedure ()
383422 {
384423 $ procedure = "apoc.json " ;
@@ -421,8 +460,10 @@ public function testBuild()
421460
422461 $ this ->assertSame ("WITH foobar WHERE foobar " , $ statement );
423462
424- $ pathMock = $ this ->getQueryConvertableMock (Path::class, "(a)->(b) " );
425463 $ nodeMock = $ this ->getQueryConvertableMock (Node::class, "(a) " );
464+ $ nodeMock ->method ('getName ' )->willReturn ($ this ->getQueryConvertableMock (Variable::class, 'a ' ));
465+
466+ $ pathMock = $ this ->getQueryConvertableMock (Path::class, "(a)->(b) " );
426467 $ numeralMock = $ this ->getQueryConvertableMock (NumeralType::class, "12 " );
427468 $ booleanMock = $ this ->getQueryConvertableMock (BooleanType::class, "a > b " );
428469 $ propertyMock = $ this ->getQueryConvertableMock (Property::class, "a.b " );
@@ -444,7 +485,7 @@ public function testBuild()
444485 ->with (["# " => $ nodeMock ])
445486 ->build ();
446487
447- $ this ->assertSame ("MATCH (a)->(b), (a) RETURN (a) AS `#` CREATE (a)->(b), (a) CREATE (a)->(b) DELETE (a), (a) DETACH DELETE (a), (a) LIMIT 12 MERGE (a) OPTIONAL MATCH (a), (a) ORDER BY a.b, a.b DESCENDING REMOVE a.b WHERE a > b WITH (a) AS `#` " , $ statement );
488+ $ this ->assertSame ("MATCH (a)->(b), (a) RETURN a AS `#` CREATE (a)->(b), (a) CREATE (a)->(b) DELETE (a), (a) DETACH DELETE (a), (a) LIMIT 12 MERGE (a) OPTIONAL MATCH (a), (a) ORDER BY a.b, a.b DESCENDING REMOVE a.b WHERE a > b WITH a AS `#` " , $ statement );
448489 }
449490
450491 public function testBuildEmpty ()
@@ -841,6 +882,26 @@ public function testWikiExamples()
841882 $ this ->assertSame ("((nineties.released >= 1990) AND (nineties IS NOT NULL)) " , $ expression ->toQuery ());
842883 }
843884
885+ public function testAutomaticIdentifierGeneration ()
886+ {
887+ $ node = Query::node ();
888+
889+ $ this ->assertMatchesRegularExpression ('/[0-9a-f]+\.foo/ ' , $ node ->property ('foo ' )->toQuery ());
890+
891+ $ node ->named ('foo ' );
892+
893+ $ this ->assertSame ('foo.bar ' , $ node ->property ('bar ' )->toQuery ());
894+
895+ $ node = Query::node ();
896+ $ statement = Query::new ()->match ($ node )->returning ($ node )->build ();
897+
898+ $ this ->assertMatchesRegularExpression ('/MATCH \([0-9a-f]+\) RETURN [0-9a-f]+/ ' , $ statement );
899+
900+ $ node = Query::node ();
901+
902+ $ this ->assertInstanceOf (Variable::class, $ node ->getName ());
903+ }
904+
844905 public function provideLiteralData (): array
845906 {
846907 return [
0 commit comments