Skip to content

Commit

Permalink
Handle proxy URLs for Cypher endpoint. Closes #63
Browse files Browse the repository at this point in the history
  • Loading branch information
jadell committed Sep 5, 2012
1 parent 6577edb commit c56b123
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/Everyman/Neo4j/Command/ExecuteCypherQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function getPath()
throw new Exception('Cypher unavailable');
}

return str_replace($this->getTransport()->getEndpoint(), '', $url);
return preg_replace('/^.+\/db\/data/', '', $url);
}

/**
Expand Down
41 changes: 39 additions & 2 deletions tests/unit/lib/Everyman/Neo4j/Client_CypherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,44 @@ public function testCypherQuery_NewEndpoint($returnValue, $resultCount)
$this->assertInstanceOf('\Everyman\Neo4j\Query\ResultSet', $result);
$this->assertEquals(count($result), $resultCount);
}


/**
* Test for http://github.com/jadell/neo4jphp/issues/63
* @dataProvider dataProvider_TestCypherQuery
*/
public function testCypherQuery_ProxyHost($returnValue, $resultCount)
{
$proxyEndpoint = 'http://proxy.me:1234/db/data';
$transport = $this->getMock('Everyman\Neo4j\Transport');
$transport->expects($this->any())
->method('getEndpoint')
->will($this->returnValue($proxyEndpoint));
$client = new Client($transport);

$props = array(
'query' => 'START a=({start}) MATCH (a)->(b) WHERE b.name = {name} RETURN b',
'params' => array('start' => 1, 'name' => 'friend name'),
);

$transport->expects($this->once())
->method('get')
->with('/')
->will($this->returnValue(array('code'=>200, 'data'=>array(
'neo4j_version' => '1.5.foo',
'cypher' => $this->endpoint.'/cypher',
))));
$transport->expects($this->once())
->method('post')
->with('/cypher', $props)
->will($this->returnValue($returnValue));

$query = new Cypher\Query($client, $props['query'], $props['params']);

$result = $client->executeCypherQuery($query);
$this->assertInstanceOf('\Everyman\Neo4j\Query\ResultSet', $result);
$this->assertEquals(count($result), $resultCount);
}

public function dataProvider_TestCypherQuery()
{
$return = array(
Expand All @@ -86,7 +123,7 @@ public function dataProvider_TestCypherQuery()
array('Brenda', 14)
)
);

return array(
array(array('code'=>204,'data'=>null), 0),
array(array('code'=>200,'data'=>$return), 3),
Expand Down

0 comments on commit c56b123

Please sign in to comment.