Completed
Push — master ( a60b4d...2e3006 )
by Michal
12:04 queued 08:36
created

ShapeMoFilesTest::provideFiles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 4
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 7
rs 9.4285
1
<?php
2
use ShapeFile\ShapeFile;
3
use ShapeFile\ShapeRecord;
4
5
class ShapeMoFilesTest extends PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
6
{
7
    /**
8
     * Tests loading of a file
9
     *
10
     * @param string  $filename Name of file
11
     * @param integer $records  Expected number of records
12
     *
13
     * @return void
14
     *
15
     * @dataProvider provideFiles
16
     */
17
    public function testLoad($filename, $records)
18
    {
19
        $shp = new ShapeFile(1);
20
        $shp->loadFromFile($filename);
21
        $this->assertEquals($records, count($shp->records));
22
    }
23
24
    /**
25
     * Data provider for file loading tests.
26
     *
27
     * @return array
28
     */
29
    public function provideFiles()
30
    {
31
        return array(
32
            array('data/capitals.*', 652),
33
            array('data/mexico.*', 32),
34
        );
35
    }
36
37
    /**
38
     * Tests creating file
39
     *
40
     * @return void
41
     */
42
    public function testCreate()
43
    {
44
        $shp = new ShapeFile(1);
45
46
        $record0 = new ShapeRecord(1);
47
        $record0->addPoint(array("x" => 482131.764567, "y" => 2143634.39608));
48
49
        $record1 = new ShapeRecord(1);
50
        $record1->addPoint(array("x" => 472131.764567, "y" => 2143634.39608));
51
52
        $record2 = new ShapeRecord(1);
53
        $record2->addPoint(array("x" => 492131.764567, "y" => 2143634.39608));
54
55
        $shp->addRecord($record0);
56
        $shp->addRecord($record1);
57
        $shp->addRecord($record2);
58
59
        $shp->setDBFHeader(
60
            array(
61
                array('ID', 'N', 8, 0),
62
                array('DESC', 'C', 50, 0)
63
            )
64
        );
65
66
        $shp->records[0]->DBFData['ID'] = '1';
67
        $shp->records[0]->DBFData['DESC'] = 'AAAAAAAAA';
68
69
        $shp->records[1]->DBFData['ID'] = '2';
70
        $shp->records[1]->DBFData['DESC'] = 'BBBBBBBBBB';
71
72
        $shp->records[2]->DBFData['ID'] = '3';
73
        $shp->records[2]->DBFData['DESC'] = 'CCCCCCCCCCC';
74
75
        $shp->saveToFile('./data/test_shape.*');
76
77
        $shp = new ShapeFile(1);
78
        $shp->loadFromFile('./data/test_shape.*');
79
        $this->assertEquals(3, count($shp->records));
80
    }
81
}
82