Skip to content

Commit 9084447

Browse files
authored
Merge pull request #204 from viktorprogger/v0.9.x
Fix automatic vertex ID generation when using vertex IDs with strings
2 parents 7aab7da + fedd7e9 commit 9084447

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Graph.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ private function getNextId()
289289
}
290290

291291
// auto ID
292-
return max(array_keys($this->verticesStorage))+1;
292+
return max(array_map('intval', array_keys($this->verticesStorage)))+1;
293293
}
294294

295295
/**

tests/GraphTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
class GraphTest extends AbstractAttributeAwareTest
1111
{
12+
/** @var Graph */
13+
private $graph;
14+
1215
/**
1316
* @before
1417
*/
@@ -17,6 +20,17 @@ public function setUpGraph()
1720
$this->graph = new Graph();
1821
}
1922

23+
public function testMixedIds()
24+
{
25+
$vertexString = $this->graph->createVertex('test');
26+
$vertex1 = $this->graph->createVertex();
27+
$vertex2 = $this->graph->createVertex();
28+
29+
self::assertEquals('test', $vertexString->getId());
30+
self::assertEquals(1, $vertex1->getId());
31+
self::assertEquals(2, $vertex2->getId());
32+
}
33+
2034
public function testVertexClone()
2135
{
2236
$graph = new Graph();

0 commit comments

Comments
 (0)