Skip to content

Commit f5befb2

Browse files
committed
Merge branch 'issue_149' of github.com:stefanak-michal/neo4j-php-client
2 parents de532f9 + 178ffa6 commit f5befb2

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/Types/AbstractCypherSequence.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ public function valid(): bool
443443
public function rewind(): void
444444
{
445445
$this->currentPosition = max(
446-
$this->currentPosition - $this->cacheLimit,
446+
$this->currentPosition - $this->cacheLimit - 1,
447447
0
448448
);
449449
}
@@ -481,7 +481,7 @@ public function key()
481481
*/
482482
protected function cacheKey()
483483
{
484-
return $this->keyCache[$this->currentPosition % $this->cacheLimit];
484+
return $this->keyCache[$this->currentPosition % max($this->cacheLimit - 1, 1)];
485485
}
486486

487487
/**

tests/Integration/ClientIntegrationTest.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,21 +314,29 @@ public function testValidConnectionCheck(string $alias): void
314314
/**
315315
* @dataProvider connectionAliases
316316
*/
317-
public function testFetchSize(string $connection): void
317+
public function testFetchSize(string $alias): void
318318
{
319-
$session = $this->getClient()->getDriver($connection)->createSession(SessionConfiguration::default()->withFetchSize(1));
319+
$this->fetchSize($alias, 1);
320+
$this->fetchSize($alias, 4);
321+
$this->fetchSize($alias, 10);
322+
}
323+
324+
public function fetchSize(string $connection, int $fetchSize): void
325+
{
326+
$session = $this->getClient()->getDriver($connection)->createSession(SessionConfiguration::default()->withFetchSize($fetchSize));
320327
$session->run('MATCH (x) DETACH DELETE x');
321328

322-
// Add 4000 user nodes
323-
for ($i = 0; $i < 4; ++$i) {
329+
$nodesAmount = $fetchSize * 4;
330+
// Add user nodes
331+
for ($i = 0; $i < $nodesAmount; ++$i) {
324332
$session->run('CREATE (user:User)');
325333
}
326334

327335
// Confirm that the database contains 4000 unique user nodes
328336
$userCountResults = $session->run('MATCH (user:User) RETURN COUNT(DISTINCT(ID(user))) as user_count');
329337
$userCount = $userCountResults->getAsCypherMap(0)->getAsInt('user_count');
330338

331-
$this->assertEquals(4, $userCount);
339+
$this->assertEquals($nodesAmount, $userCount);
332340

333341
// Retrieve the ids of all user nodes
334342
$results = $session->run('MATCH (user:User) RETURN ID(user) AS id');
@@ -339,12 +347,12 @@ public function testFetchSize(string $connection): void
339347
$userIds[] = $result->get('id');
340348
}
341349

342-
$this->assertCount(4, $userIds);
350+
$this->assertCount($nodesAmount, $userIds);
343351

344352
// Check if we have any duplicate ids by removing duplicate values
345353
// from the array.
346354
$uniqueUserIds = array_unique($userIds);
347355

348-
$this->assertCount(4, $uniqueUserIds);
356+
$this->assertCount($nodesAmount, $uniqueUserIds);
349357
}
350358
}

0 commit comments

Comments
 (0)