77
88class MultiPolygonTest extends BaseTestCase
99{
10- /**
11- * @var MultiPolygon
12- */
13- private $ multiPolygon ;
14-
15- protected function setUp ()
16- {
17- $ collection1 = new LineString (
18- [
19- new Point (0 , 0 ),
20- new Point (0 , 1 ),
21- new Point (1 , 1 ),
22- new Point (1 , 0 ),
23- new Point (0 , 0 ),
24- ]
25- );
26-
27- $ collection2 = new LineString (
28- [
29- new Point (10 , 10 ),
30- new Point (10 , 20 ),
31- new Point (20 , 20 ),
32- new Point (20 , 10 ),
33- new Point (10 , 10 ),
34- ]
35- );
36-
37- $ polygon1 = new Polygon ([$ collection1 , $ collection2 ]);
38-
39- $ collection3 = new LineString (
40- [
41- new Point (100 , 100 ),
42- new Point (100 , 200 ),
43- new Point (200 , 200 ),
44- new Point (200 , 100 ),
45- new Point (100 , 100 ),
46- ]
47- );
48-
49- $ polygon2 = new Polygon ([$ collection3 ]);
50-
51- $ this ->multiPolygon = new MultiPolygon ([$ polygon1 , $ polygon2 ]);
52- }
53-
5410 public function testFromWKT ()
5511 {
5612 $ polygon = MultiPolygon::fromWKT (
@@ -65,7 +21,7 @@ public function testToWKT()
6521 {
6622 $ this ->assertEquals (
6723 'MULTIPOLYGON(((0 0,1 0,1 1,0 1,0 0),(10 10,20 10,20 20,10 20,10 10)),((100 100,200 100,200 200,100 200,100 100))) ' ,
68- $ this ->multiPolygon ->toWKT ()
24+ $ this ->getMultiPolygon () ->toWKT ()
6925 );
7026 }
7127
@@ -89,10 +45,66 @@ public function testIssue12()
8945
9046 public function testJsonSerialize ()
9147 {
92- $ this ->assertInstanceOf (\GeoJson \Geometry \MultiPolygon::class, $ this ->multiPolygon ->jsonSerialize ());
48+ $ this ->assertInstanceOf (\GeoJson \Geometry \MultiPolygon::class, $ this ->getMultiPolygon () ->jsonSerialize ());
9349 $ this ->assertSame (
9450 '{"type":"MultiPolygon","coordinates":[[[[0,0],[1,0],[1,1],[0,1],[0,0]],[[10,10],[20,10],[20,20],[10,20],[10,10]]],[[[100,100],[200,100],[200,200],[100,200],[100,100]]]]} ' ,
95- json_encode ($ this ->multiPolygon )
51+ json_encode ($ this ->getMultiPolygon () )
9652 );
9753 }
54+
55+ public function testInvalidArgumentExceptionNotArrayOfLineString () {
56+ $ this ->expectException (InvalidArgumentException::class);
57+ $ multipolygon = new MultiPolygon ([
58+ $ this ->getPolygon1 (),
59+ $ this ->getLineString1 ()
60+ ]);
61+ }
62+
63+ private function getMultiPolygon () {
64+ return new MultiPolygon ([$ this ->getPolygon1 (), $ this ->getPolygon2 ()]);
65+ }
66+
67+ private function getLineString1 () {
68+ return new LineString (
69+ [
70+ new Point (0 , 0 ),
71+ new Point (0 , 1 ),
72+ new Point (1 , 1 ),
73+ new Point (1 , 0 ),
74+ new Point (0 , 0 ),
75+ ]
76+ );
77+ }
78+
79+ private function getLineString2 () {
80+ return new LineString (
81+ [
82+ new Point (10 , 10 ),
83+ new Point (10 , 20 ),
84+ new Point (20 , 20 ),
85+ new Point (20 , 10 ),
86+ new Point (10 , 10 ),
87+ ]
88+ );
89+ }
90+
91+ private function getLineString3 () {
92+ return new LineString (
93+ [
94+ new Point (100 , 100 ),
95+ new Point (100 , 200 ),
96+ new Point (200 , 200 ),
97+ new Point (200 , 100 ),
98+ new Point (100 , 100 ),
99+ ]
100+ );
101+ }
102+
103+ private function getPolygon1 () {
104+ return new Polygon ([$ this ->getLineString1 (), $ this ->getLineString2 ()]);
105+ }
106+
107+ private function getPolygon2 () {
108+ return new Polygon ([$ this ->getLineString3 ()]);
109+ }
98110}
0 commit comments