Completed
Push — master ( 2220ce...7d457a )
by Michal
04:37 queued 46s
created

ShapeFileTest::provideFiles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 6
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 9
rs 9.6666
1
<?php
2
use ShapeFile\ShapeFile;
3
use ShapeFile\ShapeRecord;
4
5
class ShapeFileTest 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
     * @param integer $parts    Expected number of parts in first record
13
     *
14
     * @return void
15
     *
16
     * @dataProvider provideFiles
17
     */
18
    public function testLoad($filename, $records, $parts)
19
    {
20
        $shp = new ShapeFile(1);
21
        $shp->loadFromFile($filename);
22
        $this->assertEquals($records, count($shp->records));
23
        if (!is_null($parts)) {
24
            $this->assertEquals($parts, count($shp->records[0]->SHPData["parts"]));
25
        }
26
        $this->assertEquals('', $shp->lastError);
27
    }
28
29
    /**
30
     * Data provider for file loading tests.
31
     *
32
     * @return array
33
     */
34
    public function provideFiles()
35
    {
36
        return array(
37
            array('data/capitals.*', 652, null),
38
            array('data/mexico.*', 32, 3),
39
            array('data/Czech_Republic_AL2.*', 1, 1),
40
            array('data/w001n05f.*', 1, 1),
41
        );
42
    }
43
44
    /**
45
     * Test error handling in loader
46
     *
47
     * @param string $filename name to load
48
     *
49
     * @return void
50
     *
51
     * @dataProvider provideErrorFiles
52
     */
53
    public function testLoadError($filename)
54
    {
55
        $shp = new ShapeFile(1);
56
        $shp->loadFromFile($filename);
57
        $this->assertNotEquals('', $shp->lastError);
58
    }
59
60
    /**
61
     * Data provider for file loading error tests.
62
     *
63
     * @return array
64
     */
65
    public function provideErrorFiles()
66
    {
67
        return array(
68
            array('data/no-dbf.*'),
69
            array('data/no-shp.*'),
70
            array('data/invalid-dbf.*'),
71
            array('data/missing.*'),
72
        );
73
    }
74
75
    /**
76
     * Tests creating file
77
     *
78
     * @return void
79
     */
80
    public function testCreate()
81
    {
82
        $shp = new ShapeFile(1);
83
84
        $record0 = new ShapeRecord(1);
85
        $record0->addPoint(array("x" => 482131.764567, "y" => 2143634.39608));
86
87
        $record1 = new ShapeRecord(1);
88
        $record1->addPoint(array("x" => 472131.764567, "y" => 2143634.39608));
89
90
        $record2 = new ShapeRecord(1);
91
        $record2->addPoint(array("x" => 492131.764567, "y" => 2143634.39608));
92
93
        $shp->addRecord($record0);
94
        $shp->addRecord($record1);
95
        $shp->addRecord($record2);
96
97
        $shp->setDBFHeader(
98
            array(
99
                array('ID', 'N', 8, 0),
100
                array('DESC', 'C', 50, 0)
101
            )
102
        );
103
104
        $shp->records[0]->DBFData['ID'] = '1';
105
        $shp->records[0]->DBFData['DESC'] = 'AAAAAAAAA';
106
107
        $shp->records[1]->DBFData['ID'] = '2';
108
        $shp->records[1]->DBFData['DESC'] = 'BBBBBBBBBB';
109
110
        $shp->records[2]->DBFData['ID'] = '3';
111
        $shp->records[2]->DBFData['DESC'] = 'CCCCCCCCCCC';
112
113
        $shp->saveToFile('./data/test_shape.*');
114
115
        $shp = new ShapeFile(1);
116
        $shp->loadFromFile('./data/test_shape.*');
117
        $this->assertEquals(3, count($shp->records));
118
    }
119
}
120