From a7e5153e97ed223dce02182067322a1af0f8bb41 Mon Sep 17 00:00:00 2001 From: Louis-Philippe Huberdeau Date: Mon, 25 Feb 2013 18:30:16 -0500 Subject: [PATCH] Handle paths from cypher results --- lib/HireVoice/Neo4j/Query/Cypher.php | 3 ++ lib/HireVoice/Neo4j/Tests/PathFinderTest.php | 34 ++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/lib/HireVoice/Neo4j/Query/Cypher.php b/lib/HireVoice/Neo4j/Query/Cypher.php index 202f71c..81ac831 100644 --- a/lib/HireVoice/Neo4j/Query/Cypher.php +++ b/lib/HireVoice/Neo4j/Query/Cypher.php @@ -23,6 +23,7 @@ namespace HireVoice\Neo4j\Query; use Everyman\Neo4j\Node; +use Everyman\Neo4j\Path; use HireVoice\Neo4j\EntityManager; class Cypher @@ -203,6 +204,8 @@ private function convertValue($value) { if ($value instanceof Node) { return $this->em->load($value); + } elseif ($value instanceof Path) { + return new \HireVoice\Neo4j\PathFinder\Path($value, $this->em); } else { return $value; } diff --git a/lib/HireVoice/Neo4j/Tests/PathFinderTest.php b/lib/HireVoice/Neo4j/Tests/PathFinderTest.php index a636904..91a67c0 100644 --- a/lib/HireVoice/Neo4j/Tests/PathFinderTest.php +++ b/lib/HireVoice/Neo4j/Tests/PathFinderTest.php @@ -179,6 +179,40 @@ public function testFindMultiplePaths($algorithm, $count) } } + public function testPathObtainedFromCypher() + { + $user1 = new Entity\User; + $user2 = new Entity\User; + $user3 = new Entity\User; + + $user1->setFirstName('Alex'); + $user2->setFirstName('Sergey'); + $user3->setFirstName('Anatoly'); + + $user1->addFriend($user2); + $user3->addFriend($user2); + + $em = $this->getEntityManager(); + + $em->persist($user1); + $em->persist($user2); + $em->persist($user3); + + $em->flush(); + + $paths = $em->createCypherQuery() + ->startWithNode('a', $user1) + ->startWithNode('b', $user3) + ->match('path = a -[*0..3]- b') + ->end('path') + ->getList(); + + $entities = $paths[0]->getEntities(); + $this->assertEquals($user1->getFirstName(), $entities[0]->getFirstName()); + $this->assertEquals($user2->getFirstName(), $entities[1]->getFirstName()); + $this->assertEquals($user3->getFirstName(), $entities[2]->getFirstName()); + } + function algorithms() { return array(