1 | <?php |
||
23 | class GeoJsonTest extends TestCase |
||
24 | { |
||
25 | /** |
||
26 | * @var GeoJson |
||
27 | */ |
||
28 | private $dumper; |
||
29 | |||
30 | public function setUp() |
||
31 | { |
||
32 | $this->dumper = new GeoJson(); |
||
33 | } |
||
34 | |||
35 | public function testDump() |
||
36 | { |
||
37 | $address = Address::createFromArray([]); |
||
38 | $expected = [ |
||
39 | 'type' => 'Feature', |
||
40 | 'geometry' => [ |
||
41 | 'type' => 'Point', |
||
42 | 'coordinates' => [0, 0], |
||
43 | ], |
||
44 | 'properties' => [ |
||
45 | 'providedBy' => 'n/a', |
||
46 | ], |
||
47 | ]; |
||
48 | |||
49 | $result = $this->dumper->dump($address); |
||
50 | |||
51 | $this->assertTrue(is_string($result)); |
||
52 | $this->assertEquals($expected, json_decode($result, true)); |
||
53 | } |
||
54 | |||
55 | public function testDumpWithData() |
||
56 | { |
||
57 | $address = Address::createFromArray([ |
||
58 | 'latitude' => 48.8631507, |
||
59 | 'longitude' => 2.3889114, |
||
60 | ]); |
||
61 | |||
62 | $expected = [ |
||
63 | 'type' => 'Feature', |
||
64 | 'geometry' => [ |
||
65 | 'type' => 'Point', |
||
66 | 'coordinates' => [2.3889114, 48.8631507], |
||
67 | ], |
||
68 | 'properties' => [ |
||
69 | 'providedBy' => 'n/a', |
||
70 | ], |
||
71 | ]; |
||
72 | |||
73 | $result = $this->dumper->dump($address); |
||
74 | |||
75 | $this->assertTrue(is_string($result)); |
||
76 | $this->assertEquals($expected, json_decode($result, true)); |
||
77 | } |
||
78 | |||
79 | public function testDumpWithBounds() |
||
80 | { |
||
81 | $address = Address::createFromArray([ |
||
82 | 'latitude' => 48.8631507, |
||
83 | 'longitude' => 2.3889114, |
||
84 | 'bounds' => [ |
||
85 | 'south' => 48.8631507, |
||
86 | 'west' => 2.3889114, |
||
87 | 'north' => 48.8631507, |
||
88 | 'east' => 2.388911, |
||
89 | ], |
||
90 | ]); |
||
91 | |||
92 | $expected = [ |
||
93 | 'type' => 'Feature', |
||
94 | 'geometry' => [ |
||
95 | 'type' => 'Point', |
||
96 | 'coordinates' => [2.3889114, 48.8631507], |
||
97 | ], |
||
98 | 'properties' => [ |
||
99 | 'providedBy' => 'n/a', |
||
100 | ], |
||
101 | 'bounds' => [ |
||
102 | 'south' => 48.8631507, |
||
103 | 'west' => 2.3889114, |
||
104 | 'north' => 48.8631507, |
||
105 | 'east' => 2.388911, |
||
106 | ], |
||
107 | ]; |
||
108 | |||
109 | $result = $this->dumper->dump($address); |
||
110 | |||
111 | $this->assertTrue(is_string($result)); |
||
112 | $this->assertEquals($expected, json_decode($result, true)); |
||
113 | } |
||
114 | |||
115 | public function testDumpWithProperties() |
||
116 | { |
||
117 | $address = Address::createFromArray([ |
||
118 | 'latitude' => 48.8631507, |
||
119 | 'longitude' => 2.3889114, |
||
120 | 'bounds' => [ |
||
121 | 'south' => 48.8631507, |
||
122 | 'west' => 2.3889114, |
||
123 | 'north' => 48.8631507, |
||
124 | 'east' => 2.388911, |
||
125 | ], |
||
126 | 'locality' => 'Paris', |
||
127 | 'country' => 'France', |
||
128 | ]); |
||
129 | |||
130 | $expected = [ |
||
131 | 'type' => 'Feature', |
||
132 | 'geometry' => [ |
||
133 | 'type' => 'Point', |
||
134 | 'coordinates' => [2.3889114, 48.8631507], |
||
135 | ], |
||
136 | 'properties' => [ |
||
137 | 'locality' => 'Paris', |
||
138 | 'country' => 'France', |
||
139 | 'providedBy' => 'n/a', |
||
140 | ], |
||
141 | 'bounds' => [ |
||
142 | 'south' => 48.8631507, |
||
143 | 'west' => 2.3889114, |
||
144 | 'north' => 48.8631507, |
||
145 | 'east' => 2.388911, |
||
146 | ], |
||
147 | ]; |
||
148 | |||
149 | $result = $this->dumper->dump($address); |
||
150 | |||
151 | $this->assertTrue(is_string($result)); |
||
152 | $this->assertEquals($expected, json_decode($result, true)); |
||
153 | } |
||
154 | } |
||
155 |