Skip to content

Commit

Permalink
Add test for saving and loading back test file
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Jun 14, 2016
1 parent 59efb54 commit bb485b9
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/ShapeFileTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
use ShapeFile\ShapeFile;
use ShapeFile\ShapeRecord;

class ShapeMoFilesTest extends PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -32,4 +33,49 @@ public function provideFiles()
array('data/mexico.*', 32),
);
}

/**
* Tests creating file
*
* @return void
*/
public function testCreate()
{
$shp = new ShapeFile(1);

$record0 = new ShapeRecord(1);
$record0->addPoint(array("x" => 482131.764567, "y" => 2143634.39608));

$record1 = new ShapeRecord(1);
$record1->addPoint(array("x" => 472131.764567, "y" => 2143634.39608));

$record2 = new ShapeRecord(1);
$record2->addPoint(array("x" => 492131.764567, "y" => 2143634.39608));

$shp->addRecord($record0);
$shp->addRecord($record1);
$shp->addRecord($record2);

$shp->setDBFHeader(
array(
array('ID', 'N', 8, 0),
array('DESC', 'C', 50, 0)
)
);

$shp->records[0]->DBFData['ID'] = '1';
$shp->records[0]->DBFData['DESC'] = 'AAAAAAAAA';

$shp->records[1]->DBFData['ID'] = '2';
$shp->records[1]->DBFData['DESC'] = 'BBBBBBBBBB';

$shp->records[2]->DBFData['ID'] = '3';
$shp->records[2]->DBFData['DESC'] = 'CCCCCCCCCCC';

$shp->saveToFile('./data/test_shape.*');

$shp = new ShapeFile(1);
$shp->loadFromFile('./data/test_shape.*');
$this->assertEquals(3, count($shp->records));
}
}

0 comments on commit bb485b9

Please sign in to comment.