Skip to content

Commit 059b596

Browse files
committed
Fix readSHP and add a test case
Signed-off-by: William Desportes <[email protected]>
1 parent 28ca8c7 commit 059b596

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/ShapeFile.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,10 @@ public function setError(string $error): void
660660
*/
661661
public function readSHP(int $bytes)
662662
{
663+
if ($this->shpFile === null) {
664+
return false;
665+
}
666+
663667
return fread($this->shpFile, $bytes);
664668
}
665669

tests/ShapeFileTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ public function testLoadError(string $filename): void
109109
$this->assertNotEquals('', $shp->lastError);
110110
}
111111

112+
/**
113+
* Test load an empty file name
114+
*/
115+
public function testLoadEmptyFilename(): void
116+
{
117+
$shp = new ShapeFile(1);
118+
$shp->loadFromFile('');
119+
$this->assertEquals('Not a SHP file (file code mismatch)', $shp->lastError);
120+
}
121+
112122
/**
113123
* Data provider for file loading error tests.
114124
*

0 commit comments

Comments
 (0)