Skip to content

Commit fd87e95

Browse files
fixed usage of fetchSize for amount bigger than fetched size.
1 parent 395c134 commit fd87e95

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-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: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,22 +313,36 @@ public function testValidConnectionCheck(string $alias): void
313313

314314
/**
315315
* @dataProvider connectionAliases
316+
* @param string $alias
316317
*/
317-
public function testFetchSize(string $connection): void
318+
public function testFetchSize(string $alias): void
318319
{
319-
$session = $this->getClient()->getDriver($connection)->createSession(SessionConfiguration::default()->withFetchSize(1));
320+
$this->fetchSize($alias, 1);
321+
$this->fetchSize($alias, 4);
322+
$this->fetchSize($alias, 10);
323+
}
324+
325+
/**
326+
* @param string $connection
327+
* @param int $fetchSize
328+
* @return void
329+
*/
330+
public function fetchSize(string $connection, int $fetchSize): void
331+
{
332+
$session = $this->getClient()->getDriver($connection)->createSession(SessionConfiguration::default()->withFetchSize($fetchSize));
320333
$session->run('MATCH (x) DETACH DELETE x');
321334

322-
// Add 4000 user nodes
323-
for ($i = 0; $i < 4; ++$i) {
335+
$nodesAmount = $fetchSize * 4;
336+
// Add user nodes
337+
for ($i = 0; $i < $nodesAmount; ++$i) {
324338
$session->run('CREATE (user:User)');
325339
}
326340

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

331-
$this->assertEquals(4, $userCount);
345+
$this->assertEquals($nodesAmount, $userCount);
332346

333347
// Retrieve the ids of all user nodes
334348
$results = $session->run('MATCH (user:User) RETURN ID(user) AS id');
@@ -339,12 +353,12 @@ public function testFetchSize(string $connection): void
339353
$userIds[] = $result->get('id');
340354
}
341355

342-
$this->assertCount(4, $userIds);
356+
$this->assertCount($nodesAmount, $userIds);
343357

344358
// Check if we have any duplicate ids by removing duplicate values
345359
// from the array.
346360
$uniqueUserIds = array_unique($userIds);
347361

348-
$this->assertCount(4, $uniqueUserIds);
362+
$this->assertCount($nodesAmount, $uniqueUserIds);
349363
}
350364
}

0 commit comments

Comments
 (0)