Skip to content

Commit

Permalink
Merge remote-tracking branch 'petitphilou/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
lphuberdeau committed Apr 30, 2014
2 parents 7be67cc + 6901f07 commit 94afee9
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/HireVoice/Neo4j/Query/Cypher.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ protected function appendToQuery($clause, $args)
}
break;
case 'using':
case 'optional match':
$this->query .= PHP_EOL . $clause . ' ' . implode(PHP_EOL . $clause . ' ', $args);
break;
case 'union':
$this->query .= PHP_EOL . $clause . ( $args === true ? " all" : "");
break;
case 'start':
case 'match':
case 'optional match':
case 'with':
case 'return':
case 'order by':
Expand Down
63 changes: 57 additions & 6 deletions lib/HireVoice/Neo4j/Tests/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function setUp()
$legolas = new Entity\Person;
$legolas->setFirstName('Orlando');
$legolas->setLastName('Bloom');
$legolas->addFriend($aragorn);

$root = new Entity\Movie;
$root->setTitle('Return of the king');
Expand Down Expand Up @@ -406,17 +407,67 @@ function testCypherSkiping()
/**
* @group neo4j-v2
*/
function testCypherOptionalMatch()
function testCypherOptionalMatchWithFullPath()
{
$em = $this->getEntityManager();
$result = $em->createCypherQuery()
->optionalMatch('(movie) -[:actor]-> (actor)')
->optionalMatch('(actor) --> (x)')
->end('x')
->getList();
->startWithNode('movie', self::$root)
->optionalMatch('(movie) -[:actor]-> (actor) -[:friend]-> (x)')
->end('actor.firstName as n1,x.firstName as n2')
->getResult();

$this->assertEquals(array(
array(
"n1" => "Orlando",
"n2" => "Viggo"
)
), $result->toArray());
}

/**
* @group neo4j-v2
*/
function testCypherOptionalMatchConcatened()
{
$em = $this->getEntityManager();
$result = $em->createCypherQuery()
->startWithNode('movie', self::$root)
->optionalMatch('(movie) -[:actor]-> (actor), (actor) -[:friend]-> (x)')
->end('actor.firstName as n1,x.firstName as n2')
->getResult();

$this->assertEquals(array(
null,
array(
"n1" => "Orlando",
"n2" => "Viggo"
)
), $result->toArray());
}

/**
* @group neo4j-v2
*/
function testCypherMultipleOptionalMatchClauses()
{
$em = $this->getEntityManager();
$result = $em->createCypherQuery()
->startWithNode('movie', self::$root)
->optionalMatch('(movie) -[:actor]-> (actor)')
->optionalMatch('(actor) -[:friend]-> (x)')
->end('actor.firstName as n1,x.firstName as n2')
->getResult();

$this->assertEquals(array(
//Viggo has no friend but he's returned
array(
"n1" => "Viggo",
"n2" => null,
),
//Orlando with his friend Viggo
array(
"n1" => "Orlando",
"n2" => "Viggo"
)
), $result->toArray());
}
}

0 comments on commit 94afee9

Please sign in to comment.