Skip to content

Commit 0945e8b

Browse files
author
Jan Steemann
committed
adjusted tests for 2.6/2.7
1 parent e46ea86 commit 0945e8b

File tree

7 files changed

+96
-176
lines changed

7 files changed

+96
-176
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# ArangoDB-PHP - A PHP client for ArangoDB
44

55
[![Build Status](https://travis-ci.org/arangodb/arangodb-php.png?branch=master)](https://travis-ci.org/arangodb/arangodb-php)
6-
**Branch: Master (v2.5)**
6+
**Branch: Master (v2.6)**
77

88
[![Build Status](https://travis-ci.org/arangodb/arangodb-php.png?branch=devel)](https://travis-ci.org/arangodb/arangodb-php)
99
**Branch: devel**

lib/triagens/ArangoDb/Cursor.php

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -343,16 +343,16 @@ public function valid()
343343
* @return void
344344
*/
345345
private function add(array $data)
346-
{
346+
{
347347
foreach ($this->sanitize($data) as $row) {
348-
349348
if ((isset($this->_options[self::ENTRY_FLAT]) && $this->_options[self::ENTRY_FLAT]) || !is_array($row)) {
350349
$this->addFlatFromArray($row);
351-
} else {
350+
}
351+
else {
352352
if (!isset($this->_options['objectType'])) {
353353
$this->addDocumentsFromArray($row);
354-
} else {
355-
354+
}
355+
else {
356356
switch ($this->_options['objectType']) {
357357
case 'edge' :
358358
$this->addEdgesFromArray($row);
@@ -446,25 +446,34 @@ private function addPathsFromArray(array $data)
446446
*/
447447
private function addShortestPathFromArray(array $data)
448448
{
449+
if (! isset($data["vertices"])) {
450+
return;
451+
}
452+
453+
$vertices = $data["vertices"];
454+
$startVertex = $vertices[0];
455+
$destination = $vertices[count($vertices) - 1];
456+
449457
$entry = array(
450458
"paths" => array (),
451-
"source" => $data["startVertex"],
459+
"source" => Document::createFromArray($startVertex, $this->_options),
452460
"distance" => $data["distance"],
453-
"destination" => Document::createFromArray($data["vertex"], $this->_options),
461+
"destination" => Document::createFromArray($destination, $this->_options),
454462
);
455-
foreach ($data["paths"] as $p) {
456-
$path = array (
463+
464+
$path = array (
457465
"vertices" => array(),
458466
"edges" => array()
459-
);
460-
foreach ($p["vertices"] as $v) {
461-
$path["vertices"][] = $v;
462-
}
463-
foreach ($p["edges"] as $v) {
464-
$path["edges"][] = Edge::createFromArray($v, $this->_options);
465-
}
466-
$entry["paths"][] = $path;
467+
);
468+
469+
foreach ($data["vertices"] as $v) {
470+
$path["vertices"][] = $v;
467471
}
472+
foreach ($data["edges"] as $v) {
473+
$path["edges"][] = Edge::createFromArray($v, $this->_options);
474+
}
475+
$entry["paths"][] = $path;
476+
468477
$this->_result[] = $entry;
469478
}
470479

@@ -478,12 +487,12 @@ private function addShortestPathFromArray(array $data)
478487
*/
479488
private function addDistanceToFromArray(array $data)
480489
{
481-
$entry = array(
482-
"source" => $data["startVertex"],
483-
"distance" => $data["distance"],
484-
"destination" => Document::createFromArray($data["vertex"], $this->_options),
485-
);
486-
$this->_result[] = $entry;
490+
$entry = array(
491+
"source" => $data["startVertex"],
492+
"distance" => $data["distance"],
493+
"destination" => $data["vertex"]
494+
);
495+
$this->_result[] = $entry;
487496
}
488497

489498
/**
@@ -495,15 +504,18 @@ private function addDistanceToFromArray(array $data)
495504
*/
496505
private function addCommonNeighborsFromArray(array $data)
497506
{
498-
$k = array_keys($data);
499-
$k = $k[0];
500-
$this->_result[$k] = array();
507+
$left = $data["left"];
508+
$right = $data["right"];
509+
510+
if (! isset($this->_result[$left])) {
511+
$this->_result[$left] = array();
512+
}
513+
if (! isset($this->_result[$left][$right])) {
514+
$this->_result[$left][$right] = array();
515+
}
501516

502-
foreach ($data[$k] as $neighbor => $neighbors) {
503-
$this->_result[$k][$neighbor] = array();
504-
foreach ($neighbors as $n) {
505-
$this->_result[$k][$neighbor][] = Document::createFromArray($n);
506-
}
517+
foreach ($data["neighbors"] as $neighbor) {
518+
$this->_result[$left][$right][] = Document::createFromArray($neighbor);
507519
}
508520
}
509521

lib/triagens/ArangoDb/GraphHandler.php

Lines changed: 14 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,8 +1336,8 @@ public function getNeighborVertices($graph, $vertexExample, $options = array())
13361336
$graph = $graph->getKey();
13371337
}
13381338

1339-
$options['objectType'] = 'vertex';
1340-
$data = array_merge($options, $this->getCursorOptions($options));
1339+
$options['includeData'] = true;
1340+
$options['objectType'] = 'vertex';
13411341
$filterString = 'FILTER ';
13421342
$statement = new Statement($this->getConnection(), array(
13431343
"query" => ''
@@ -1353,38 +1353,7 @@ public function getNeighborVertices($graph, $vertexExample, $options = array())
13531353
}
13541354
$options['direction'] = $options['filter']['direction'];
13551355
}
1356-
if (isset($options['filter']) && isset($options['filter']['properties'])) {
1357-
if (!isset($options['filter']['properties'][0])) {
1358-
$tmp = $options['filter']['properties'];
1359-
$options['filter']['properties'] = array();
1360-
$options['filter']['properties'][0] = $tmp;
1361-
}
1362-
$i = 0;
1363-
foreach ($options['filter']['properties'] as $filter) {
1364-
$i++;
1365-
switch ($filter['compare']) {
1366-
case "HAS":
1367-
$aql .= $filterString . "HAS(a.path.edges[0], @key" . $i . ") ";
1368-
$statement->bind('key' . $i, $filter['key']);
1369-
break;
1370-
case "HAS_NOT":
1371-
$aql .= $filterString . "!HAS(a.path.edges[0], @key" . $i . ") ";
1372-
$statement->bind('key' . $i, $filter['key']);
1373-
break;
1374-
default:
1375-
$aql .= $filterString . "a.path.edges[0][@key" . $i . "] " . $filter['compare'] . " @value" . $i;
1376-
$statement->bind('key' . $i, $filter['key']);
1377-
$statement->bind('value' . $i, $filter['value']);
1378-
break;
1379-
}
1380-
$filterString = ' && ';
1381-
}
1382-
}
13831356

1384-
if (isset($options['filter']) && isset($options['filter']['labels'])) {
1385-
$aql .= $filterString . 'a.path.edges[0]["$label"] IN @labels ';
1386-
$statement->bind('labels', $options['filter']['labels']);
1387-
}
13881357
unset($options['filter']);
13891358
$statement->bind('graphName', $graph);
13901359
$statement->bind('vertex', $vertexExample);
@@ -1414,7 +1383,7 @@ public function getNeighborVertices($graph, $vertexExample, $options = array())
14141383
unset($this->limit);
14151384
}
14161385

1417-
$aql .= " RETURN a.vertex";
1386+
$aql .= " RETURN a";
14181387
$statement->setQuery($aql);
14191388
return $statement->execute();
14201389

@@ -1523,7 +1492,6 @@ public function getVertices($graph, $options = array())
15231492
}
15241493

15251494
$options['objectType'] = 'vertex';
1526-
$data = array_merge($options, $this->getCursorOptions($options));
15271495
$filterString = 'FILTER ';
15281496
$statement = new Statement($this->getConnection(), array(
15291497
"query" => ''
@@ -1646,8 +1614,8 @@ public function getEdges($graph, $options = array())
16461614
$graph = $graph->getKey();
16471615
}
16481616

1649-
$options['objectType'] = 'edge';
1650-
$data = array_merge($options, $this->getCursorOptions($options));
1617+
$options['objectType'] = 'edge';
1618+
$options['includeData'] = true;
16511619
$filterString = 'FILTER ';
16521620
$statement = new Statement($this->getConnection(), array(
16531621
"query" => ''
@@ -1770,7 +1738,6 @@ public function getPaths($graph, $options = array())
17701738
}
17711739

17721740
$options['objectType'] = 'path';
1773-
$data = array_merge($options, $this->getCursorOptions($options));
17741741
$statement = new Statement($this->getConnection(), array(
17751742
"query" => ''
17761743
));
@@ -1861,21 +1828,21 @@ public function getPaths($graph, $options = array())
18611828
* @return Cursor
18621829
*/
18631830
public function getShortestPaths($graph,
1864-
$startVertexExample = null,
1865-
$endVertexExample = null,
1831+
$startVertexExample = array(),
1832+
$endVertexExample = array(),
18661833
$options = array())
18671834
{
18681835
if ($graph instanceof Graph) {
18691836
$graph = $graph->getKey();
18701837
}
18711838

1872-
$options['objectType'] = 'shortestPath';
1873-
$data = array_merge($options, $this->getCursorOptions($options));
1839+
$options['includeData'] = true;
1840+
$options['objectType'] = 'shortestPath';
18741841
$statement = new Statement($this->getConnection(), array(
18751842
"query" => ''
18761843
));
18771844
$statement->setResultType($options['objectType']);
1878-
$aql = "FOR a IN GRAPH_SHORTEST_PATH(@graphName, @start, @end , @options) ";
1845+
$aql = "FOR a IN GRAPH_SHORTEST_PATH(@graphName, @start, @end, @options) ";
18791846

18801847
if (isset($options['direction'])) {
18811848
if ($options['direction'] === "in") {
@@ -1947,13 +1914,11 @@ public function getDistanceTo($graph,
19471914
}
19481915

19491916
$options['objectType'] = 'distanceTo';
1950-
$data = array_merge($options, $this->getCursorOptions($options));
19511917
$statement = new Statement($this->getConnection(), array(
1952-
"query" => '',
1953-
"_flat" => true
1918+
"query" => ''
19541919
));
19551920
$statement->setResultType($options['objectType']);
1956-
$aql = "FOR a IN GRAPH_DISTANCE_TO(@graphName, @start, @end , @options) ";
1921+
$aql = "FOR a IN GRAPH_DISTANCE_TO(@graphName, @start, @end, @options) ";
19571922

19581923
if (isset($options['direction'])) {
19591924
if ($options['direction'] === "in") {
@@ -2062,6 +2027,8 @@ public function getCommonNeighborVertices($graph, $vertex1Example = null, $verte
20622027
$statement->bind('graphName', $graph);
20632028
$statement->bind('vertex1', $vertex1Example);
20642029
$statement->bind('vertex2', $vertex2Example);
2030+
$options1['includeData'] = true;
2031+
$options2['includeData'] = true;
20652032
$statement->bind('options1', $options1);
20662033
$statement->bind('options2', $options2);
20672034
if (isset($this->batchsize)) {
@@ -2080,7 +2047,6 @@ public function getCommonNeighborVertices($graph, $vertex1Example = null, $verte
20802047
$aql .= " RETURN a";
20812048
$statement->setQuery($aql);
20822049
return $statement->execute();
2083-
20842050
}
20852051

20862052

@@ -2198,7 +2164,6 @@ public function getAbsoluteEccentricity($graph,
21982164
}
21992165

22002166
$options['objectType'] = 'figure';
2201-
$data = array_merge($options, $this->getCursorOptions($options));
22022167
$statement = new Statement($this->getConnection(), array(
22032168
"query" => ''
22042169
));
@@ -2255,7 +2220,6 @@ public function getEccentricity($graph,
22552220
}
22562221

22572222
$options['objectType'] = 'figure';
2258-
$data = array_merge($options, $this->getCursorOptions($options));
22592223
$statement = new Statement($this->getConnection(), array(
22602224
"query" => ''
22612225
));
@@ -2326,7 +2290,6 @@ public function getAbsoluteCloseness($graph,
23262290
}
23272291

23282292
$options['objectType'] = 'figure';
2329-
$data = array_merge($options, $this->getCursorOptions($options));
23302293
$statement = new Statement($this->getConnection(), array(
23312294
"query" => ''
23322295
));
@@ -2383,7 +2346,6 @@ public function getCloseness($graph,
23832346
}
23842347

23852348
$options['objectType'] = 'figure';
2386-
$data = array_merge($options, $this->getCursorOptions($options));
23872349
$statement = new Statement($this->getConnection(), array(
23882350
"query" => ''
23892351
));
@@ -2440,7 +2402,6 @@ public function getAbsoluteBetweenness($graph,
24402402
}
24412403

24422404
$options['objectType'] = 'figure';
2443-
$data = array_merge($options, $this->getCursorOptions($options));
24442405
$statement = new Statement($this->getConnection(), array(
24452406
"query" => ''
24462407
));
@@ -2494,7 +2455,6 @@ public function getBetweenness($graph, $options = array())
24942455
}
24952456

24962457
$options['objectType'] = 'figure';
2497-
$data = array_merge($options, $this->getCursorOptions($options));
24982458
$statement = new Statement($this->getConnection(), array(
24992459
"query" => '',
25002460
"_flat" => true
@@ -2552,7 +2512,6 @@ public function getRadius($graph,
25522512
}
25532513

25542514
$options['objectType'] = 'figure';
2555-
$data = array_merge($options, $this->getCursorOptions($options));
25562515
$statement = new Statement($this->getConnection(), array(
25572516
"query" => ''
25582517
));
@@ -2609,7 +2568,6 @@ public function getDiameter($graph,
26092568
}
26102569

26112570
$options['objectType'] = 'figure';
2612-
$data = array_merge($options, $this->getCursorOptions($options));
26132571
$statement = new Statement($this->getConnection(), array(
26142572
"query" => ''
26152573
));

0 commit comments

Comments
 (0)