Skip to content

Commit

Permalink
Handle paths from cypher results
Browse files Browse the repository at this point in the history
  • Loading branch information
lphuberdeau committed Feb 25, 2013
1 parent 592ce74 commit a7e5153
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/HireVoice/Neo4j/Query/Cypher.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace HireVoice\Neo4j\Query;
use Everyman\Neo4j\Node;
use Everyman\Neo4j\Path;
use HireVoice\Neo4j\EntityManager;

class Cypher
Expand Down Expand Up @@ -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;
}
Expand Down
34 changes: 34 additions & 0 deletions lib/HireVoice/Neo4j/Tests/PathFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit a7e5153

Please sign in to comment.