Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
add a max number of records to load
fixes phpmyadmin#42
  • Loading branch information
JoolsMcFly committed Dec 11, 2024
1 parent 7d8bb8b commit 6415d24
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/ShapeFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class ShapeFile

private bool $allowNoDbf = false;

private bool|int $maxRecords = false;

/**
* Checks whether dbase manipulations are supported.
*/
Expand All @@ -108,6 +110,11 @@ public function __construct(
) {
}

public function setMaxRecords(int|bool $max): void
{
$this->maxRecords = $max;
}

public function setAllowNoDbf(bool $allowNoDbf): void
{
$this->allowNoDbf = $allowNoDbf;
Expand Down Expand Up @@ -492,6 +499,10 @@ private function loadRecords(): bool
}

$this->records[] = $record;

if ($this->maxRecords !== false && count($this->records) > $this->maxRecords) {
return true;
}
}

return true;
Expand Down
14 changes: 14 additions & 0 deletions tests/ShapeFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,4 +429,18 @@ public function testAllowsNoDbf(): void
$shp->setAllowNoDbf(true);
self::assertTrue($shp->loadFromFile('data/no-dbf.*'));
}

public function testMaxNumberRecords(): void
{
if (! ShapeFile::supportsDbase()) {
self::markTestSkipped('dbase extension missing');
}

$this->createTestData();

$shp = new ShapeFile(ShapeType::Point);
$shp->setMaxRecords(5);
$shp->loadFromFile('data/mexico.*');
self::assertCount(5, $shp->records);
}
}

0 comments on commit 6415d24

Please sign in to comment.