Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added data/invalid-dbf.dbf
Empty file.
Empty file added data/invalid-dbf.shp
Empty file.
Empty file added data/invalid-dbf.shx
Empty file.
Empty file added data/no-dbf.shp
Empty file.
Empty file added data/no-dbf.shx
Empty file.
Binary file added data/no-shp.dbf
Binary file not shown.
Empty file added data/no-shp.shx
Empty file.
2 changes: 1 addition & 1 deletion src/ShapeFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ private function _openDBFFile($toWrite = false) {
}
}
if ($checkFunction(str_replace('.*', '.dbf', $this->FileName))) {
$this->DBFFile = dbase_open(str_replace('.*', '.dbf', $this->FileName), ($toWrite ? 2 : 0));
$this->DBFFile = @dbase_open(str_replace('.*', '.dbf', $this->FileName), ($toWrite ? 2 : 0));
if (!$this->DBFFile) {
return $this->setError(sprintf("It wasn't possible to open the DBase file '%s'", str_replace('.*', '.dbf', $this->FileName)));
}
Expand Down
34 changes: 33 additions & 1 deletion tests/ShapeFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function testLoad($filename, $records, $parts)
if (!is_null($parts)) {
$this->assertEquals($parts, count($shp->records[0]->SHPData["parts"]));
}
$this->assertEquals('', $shp->lastError);
}

/**
Expand All @@ -36,7 +37,38 @@ public function provideFiles()
array('data/capitals.*', 652, null),
array('data/mexico.*', 32, 3),
array('data/Czech_Republic_AL2.*', 1, 1),
array('data/data/w001n05f.*', 0, null),
array('data/w001n05f.*', 1, 1),
);
}

/**
* Test error handling in loader
*
* @param string $filename name to load
*
* @return void
*
* @dataProvider provideErrorFiles
*/
public function testLoadError($filename)
{
$shp = new ShapeFile(1);
$shp->loadFromFile($filename);
$this->assertNotEquals('', $shp->lastError);
}

/**
* Data provider for file loading error tests.
*
* @return array
*/
public function provideErrorFiles()
{
return array(
array('data/no-dbf.*'),
array('data/no-shp.*'),
array('data/invalid-dbf.*'),
array('data/missing.*'),
);
}

Expand Down