Test Failed
Push — geoRange ( 87f3d6...eb5c18 )
by no
02:44
created

testDecimalMinuteNotationRoundTrip()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 3
nc 1
nop 3
1
<?php
2
3
namespace Tests\DataValues\Geo\Formatters;
4
5
use DataValues\Geo\Formatters\GeoCoordinateFormatter;
6
use DataValues\Geo\Parsers\GeoCoordinateParser;
7
use DataValues\Geo\Values\LatLongValue;
8
use DataValues\StringValue;
9
use ValueFormatters\FormatterOptions;
10
11
/**
12
 * @covers DataValues\Geo\Formatters\GeoCoordinateFormatter
13
 *
14
 * @group ValueFormatters
15
 * @group DataValueExtensions
16
 *
17
 * @license GPL-2.0+
18
 * @author Jeroen De Dauw < [email protected] >
19
 * @author Addshore
20
 * @author Daniel Kinzler
21
 */
22
class GeoCoordinateFormatterTest extends \PHPUnit_Framework_TestCase {
23
24
	public function floatNotationProvider() {
25
		return array(
26
			'0, degree' => array(
27
				new LatLongValue( 0, 0 ),
28
				1,
29
				'0, 0'
30
			),
31
			'negative zero' => array(
32
				new LatLongValue( -0.25, 0.25 ),
33
				1,
34
				'0, 0'
35
			),
36
			'signed, minute' => array(
37
				new LatLongValue( -55.755786, 37.25633 ),
38
				1.0/60,
39
				'-55.75, 37.25'
40
			),
41
			'signed, degree' => array(
42
				new LatLongValue( -55.755786, 37.25633 ),
43
				1,
44
				'-56, 37'
45
			),
46
			'three degrees' => array(
47
				new LatLongValue( -55.755786, 37.25633 ),
48
				3,
49
				'-57, 36'
50
			),
51
			'seven degrees' => array(
52
				new LatLongValue( -55.755786, 37.25633 ),
53
				7,
54
				'-56, 35'
55
			),
56
			'ten degrees' => array(
57
				new LatLongValue( -55.755786, 37.25633 ),
58
				10,
59
				'-60, 40'
60
			),
61
			'rounding degrees down' => array(
62
				new LatLongValue( -14.9, 14.9 ),
63
				10,
64
				'-10, 10'
65
			),
66
			'rounding degrees up' => array(
67
				new LatLongValue( -15, 15 ),
68
				10,
69
				'-20, 20'
70
			),
71
			'rounding fractions down' => array(
72
				new LatLongValue( -0.049, 0.049 ),
73
				0.1,
74
				'0, 0'
75
			),
76
			'rounding fractions up' => array(
77
				new LatLongValue( -0.05, 0.05 ),
78
				0.1,
79
				'-0.1, 0.1'
80
			),
81
			'precision option must support strings' => array(
82
				new LatLongValue( -0.05, 0.05 ),
83
				'0.1',
84
				'-0.1, 0.1'
85
			),
86
		);
87
	}
88
89
	/**
90
	 * @param string $format One of the GeoCoordinateFormatter::TYPE_… constants
91
	 * @param float|int $precision
92
	 *
93
	 * @return FormatterOptions
94
	 */
95
	private function makeOptions( $format, $precision ) {
96
		$options = new FormatterOptions();
97
		$options->setOption( GeoCoordinateFormatter::OPT_FORMAT, $format );
98
		$options->setOption( GeoCoordinateFormatter::OPT_DIRECTIONAL, false );
99
		$options->setOption( GeoCoordinateFormatter::OPT_PRECISION, $precision );
100
101
		return $options;
102
	}
103
104
	/**
105
	 * @dataProvider floatNotationProvider
106
	 */
107
	public function testFloatNotationFormatting( LatLongValue $latLong, $precision, $expected ) {
108
		$options = $this->makeOptions( GeoCoordinateFormatter::TYPE_FLOAT, $precision );
109
		$this->assertFormatsCorrectly( $latLong, $options, $expected );
110
	}
111
112
	/**
113
	 * @dataProvider floatNotationProvider
114
	 */
115
	public function testFloatNotationRoundTrip( LatLongValue $value, $precision, $expected ) {
116
		$options = $this->makeOptions( GeoCoordinateFormatter::TYPE_FLOAT, $precision );
117
		$this->assertRoundTrip( $value, $options );
118
	}
119
120
	public function decimalDegreeNotationProvider() {
121
		return array(
122
			'0, degree' => array(
123
				new LatLongValue( 0, 0 ),
124
				1,
125
				'0°, 0°'
126
			),
127
			'negative zero' => array(
128
				new LatLongValue( -0.25, 0.25 ),
129
				1,
130
				'0°, 0°'
131
			),
132
			'signed, minute' => array(
133
				new LatLongValue( -55.755786, 37.25633 ),
134
				1.0/60,
135
				'-55.75°, 37.25°'
136
			),
137
			'signed, degree' => array(
138
				new LatLongValue( -55.755786, 37.25633 ),
139
				1,
140
				'-56°, 37°'
141
			),
142
			'three degrees' => array(
143
				new LatLongValue( -55.755786, 37.25633 ),
144
				3,
145
				'-57°, 36°'
146
			),
147
			'seven degrees' => array(
148
				new LatLongValue( -55.755786, 37.25633 ),
149
				7,
150
				'-56°, 35°'
151
			),
152
			'ten degrees' => array(
153
				new LatLongValue( -55.755786, 37.25633 ),
154
				10,
155
				'-60°, 40°'
156
			),
157
			'rounding degrees down' => array(
158
				new LatLongValue( -14.9, 14.9 ),
159
				10,
160
				'-10°, 10°'
161
			),
162
			'rounding degrees up' => array(
163
				new LatLongValue( -15, 15 ),
164
				10,
165
				'-20°, 20°'
166
			),
167
			'rounding fractions down' => array(
168
				new LatLongValue( -0.049, 0.049 ),
169
				0.1,
170
				'0.0°, 0.0°'
171
			),
172
			'rounding fractions up' => array(
173
				new LatLongValue( -0.05, 0.05 ),
174
				0.1,
175
				'-0.1°, 0.1°'
176
			),
177
			'precision option must support strings' => array(
178
				new LatLongValue( -0.05, 0.05 ),
179
				'0.1',
180
				'-0.1°, 0.1°'
181
			),
182
		);
183
	}
184
185
	/**
186
	 * @dataProvider decimalDegreeNotationProvider
187
	 */
188
	public function testDecimalDegreeNotationFormatting( LatLongValue $latLong, $precision, $expected ) {
189
		$options = $this->makeOptions( GeoCoordinateFormatter::TYPE_DD, $precision );
190
		$this->assertFormatsCorrectly( $latLong, $options, $expected );
191
	}
192
193
	/**
194
	 * @dataProvider decimalDegreeNotationProvider
195
	 */
196
	public function testDecimalDegreeNotationRoundTrip( LatLongValue $latLong, $precision, $expected ) {
197
		$options = $this->makeOptions( GeoCoordinateFormatter::TYPE_DD, $precision );
198
		$this->assertRoundTrip( $latLong, $options );
199
	}
200
201
	public function decimalMinuteNotationProvider() {
202
		return array(
203
			'0, degree' => array(
204
				new LatLongValue( 0, 0 ),
205
				1,
206
				'0°, 0°'
207
			),
208
			'0, minute' => array(
209
				new LatLongValue( 0, 0 ),
210
				1.0/60,
211
				'0° 0\', 0° 0\''
212
			),
213
			'0, second' => array(
214
				new LatLongValue( 0, 0 ),
215
				1.0/3600,
216
				'0° 0.00\', 0° 0.00\''
217
			),
218
			'negative zero' => array(
219
				new LatLongValue( -1.0/128, 1.0/128 ),
220
				1.0/60,
221
				'0° 0\', 0° 0\''
222
			),
223
			'negative, not zero' => array(
224
				new LatLongValue( -0.25, 0.25 ),
225
				1.0/60,
226
				'-0° 15\', 0° 15\''
227
			),
228
			'second' => array(
229
				new LatLongValue( -55.755786, 37.25633 ),
230
				1.0/3600,
231
				'-55° 45.35\', 37° 15.38\''
232
			),
233
			'minute' => array(
234
				new LatLongValue( -55.755786, 37.25633 ),
235
				1.0/60,
236
				'-55° 45\', 37° 15\''
237
			),
238
			'ten minutes' => array(
239
				new LatLongValue( -55.755786, 37.25633 ),
240
				10.0/60,
241
				'-55° 50\', 37° 20\''
242
			),
243
			'fifty minutes' => array(
244
				new LatLongValue( -55.755786, 37.25633 ),
245
				50.0/60,
246
				'-55° 50\', 37° 30\''
247
			),
248
			'degree' => array(
249
				new LatLongValue( -55.755786, 37.25633 ),
250
				1,
251
				'-56°, 37°'
252
			),
253
			'ten degrees' => array(
254
				new LatLongValue( -55.755786, 37.25633 ),
255
				10,
256
				'-60°, 40°'
257
			),
258
			'rounding minutes down' => array(
259
				new LatLongValue( -14.9 / 60, 14.9 / 60 ),
260
				10 / 60,
261
				'-0° 10\', 0° 10\''
262
			),
263
			'rounding minutes up' => array(
264
				new LatLongValue( -15 / 60, 15 / 60 ),
265
				10 / 60,
266
				'-0° 20\', 0° 20\''
267
			),
268
			'rounding fractions down' => array(
269
				new LatLongValue( -0.049 / 60, 0.049 / 60 ),
270
				0.1 / 60,
271
				'0° 0.0\', 0° 0.0\''
272
			),
273
			'rounding fractions up' => array(
274
				new LatLongValue( -0.05 / 60, 0.05 / 60 ),
275
				0.1 / 60,
276
				'-0° 0.1\', 0° 0.1\''
277
			),
278
			'precision option must support strings' => array(
279
				new LatLongValue( -0.05, 0.05 ),
280
				'0.1',
281
				'-0° 6\', 0° 6\''
282
			),
283
		);
284
	}
285
286
	/**
287
	 * @dataProvider decimalMinuteNotationProvider
288
	 */
289
	public function testDecimalMinuteNotationFormatting( LatLongValue $latLong, $precision, $expected ) {
290
		$options = $this->makeOptions( GeoCoordinateFormatter::TYPE_DM, $precision );
291
		$this->assertFormatsCorrectly( $latLong, $options, $expected );
292
	}
293
294
	/**
295
	 * @dataProvider decimalMinuteNotationProvider
296
	 */
297
	public function testDecimalMinuteNotationRoundTrip( LatLongValue $latLong, $precision, $expected ) {
298
		$options = $this->makeOptions( GeoCoordinateFormatter::TYPE_DM, $precision );
299
		$this->assertRoundTrip( $latLong, $options );
300
	}
301
302
	public function decimalMinuteSecondNotationProvider() {
303
		return array(
304
			'0, degree' => array(
305
				new LatLongValue( 0, 0 ),
306
				1,
307
				'0°, 0°'
308
			),
309
			'0, minute' => array(
310
				new LatLongValue( 0, 0 ),
311
				1.0/60,
312
				'0° 0\', 0° 0\''
313
			),
314
			'0, second' => array(
315
				new LatLongValue( 0, 0 ),
316
				1.0/3600,
317
				'0° 0\' 0", 0° 0\' 0"'
318
			),
319
			'negative zero' => array(
320
				new LatLongValue( -1.0/8192, 1.0/8192 ),
321
				1.0/3600,
322
				'0° 0\' 0", 0° 0\' 0"'
323
			),
324
			'negative, not zero' => array(
325
				new LatLongValue( -1.0/4096, 1.0/4096 ),
326
				1.0/7200,
327
				'-0° 0\' 1.0", 0° 0\' 1.0"'
328
			),
329
			'second' => array(
330
				new LatLongValue( -55.755786, 37.25 ),
331
				1.0/3600,
332
				'-55° 45\' 21", 37° 15\' 0"'
333
			),
334
			'second/100' => array(
335
				new LatLongValue( -55.755786, 37.25633 ),
336
				1.0/360000,
337
				'-55° 45\' 20.83", 37° 15\' 22.79"'
338
			),
339
			'ten seconds' => array(
340
				new LatLongValue( -55.755786, 37.25633 ),
341
				10.0/3600,
342
				'-55° 45\' 20", 37° 15\' 20"'
343
			),
344
			'fifty seconds' => array(
345
				new LatLongValue( -55.755786, 37.25633 ),
346
				50.0/3600,
347
				'-55° 45\' 0", 37° 15\' 0"'
348
			),
349
			'minute' => array(
350
				new LatLongValue( -55.755786, 37.25633 ),
351
				1.0/60,
352
				'-55° 45\', 37° 15\''
353
			),
354
			'degree' => array(
355
				new LatLongValue( -55.755786, 37.25633 ),
356
				1,
357
				'-56°, 37°'
358
			),
359
			'degree/100, case A' => array(
360
				new LatLongValue( 52.01, 10.01 ),
361
				0.01,
362
				'52° 0\' 36", 10° 0\' 36"'
363
			),
364
			'degree/100, case B' => array(
365
				new LatLongValue( 52.02, 10.02 ),
366
				0.01,
367
				'52° 1\' 12", 10° 1\' 12"'
368
			),
369
			'ten degrees' => array(
370
				new LatLongValue( -55.755786, 37.25633 ),
371
				10,
372
				'-60°, 40°'
373
			),
374
			'rounding seconds down' => array(
375
				new LatLongValue( -14.9 / 3600, 14.9 / 3600 ),
376
				10 / 3600,
377
				'-0° 0\' 10", 0° 0\' 10"'
378
			),
379
			'rounding seconds up' => array(
380
				new LatLongValue( -15 / 3600, 15 / 3600 ),
381
				10 / 3600,
382
				'-0° 0\' 20", 0° 0\' 20"'
383
			),
384
			'rounding fractions down' => array(
385
				new LatLongValue( -0.049 / 3600, 0.049 / 3600 ),
386
				0.1 / 3600,
387
				'0° 0\' 0.0", 0° 0\' 0.0"'
388
			),
389
			'rounding fractions up' => array(
390
				new LatLongValue( -0.05 / 3600, 0.05 / 3600 ),
391
				0.1 / 3600,
392
				'-0° 0\' 0.1", 0° 0\' 0.1"'
393
			),
394
			'precision option must support strings' => array(
395
				new LatLongValue( -0.05, 0.05 ),
396
				'0.1',
397
				'-0° 6\', 0° 6\''
398
			),
399
		);
400
	}
401
402
	/**
403
	 * @dataProvider decimalMinuteSecondNotationProvider
404
	 */
405
	public function testDecimalMinuteSecondNotationFormatting( LatLongValue $latLong, $precision, $expected ) {
406
		$options = $this->makeOptions( GeoCoordinateFormatter::TYPE_DMS, $precision );
407
		$this->assertFormatsCorrectly( $latLong, $options, $expected );
408
	}
409
410
	/**
411
	 * @dataProvider decimalMinuteSecondNotationProvider
412
	 */
413
	public function testDecimalMinuteSecondNotationRoundTrip( LatLongValue $latLong, $precision, $expected ) {
414
		$options = $this->makeOptions( GeoCoordinateFormatter::TYPE_DMS, $precision );
415
		$this->assertRoundTrip( $latLong, $options );
416
	}
417
418
	/**
419
	 * @param LatLongValue $latLong
420
	 * @param FormatterOptions $options
421
	 * @param string $expected
422
	 */
423
	private function assertFormatsCorrectly( LatLongValue $latLong, FormatterOptions $options, $expected ) {
424
		$formatter = new GeoCoordinateFormatter( $options );
425
426
		$this->assertSame(
427
			$expected,
428
			$formatter->format( $latLong ),
429
			'format()'
430
		);
431
432
		$precision = $options->getOption( GeoCoordinateFormatter::OPT_PRECISION );
433
		$this->assertSame(
434
			$expected,
435
			$formatter->formatLatLongValue( $latLong, $precision ),
436
			'formatLatLongValue()'
437
		);
438
	}
439
440
	private function assertRoundTrip( LatLongValue $value, FormatterOptions $options ) {
441
		$formatter = new GeoCoordinateFormatter( $options );
442
		$parser = new GeoCoordinateParser();
443
444
		$formatted = $formatter->format( $value );
445
		$parsed = $parser->parse( $formatted );
446
447
		// NOTE: $parsed may be != $coord, because of rounding, so we can't compare directly.
448
		$formattedParsed = $formatter->format( $parsed );
449
450
		$this->assertSame( $formatted, $formattedParsed );
451
	}
452
453
	public function testDirectionalOptionGetsAppliedForDecimalMinutes() {
454
		$coordinates = array(
455
			'55° 0\' N, 37° 0\' E' => array( 55, 37 ),
456
			'55° 30\' N, 37° 30\' W' => array( 55.5, -37.5 ),
457
			'55° 30\' S, 37° 30\' E' => array( -55.5, 37.5 ),
458
			'55° 30\' S, 37° 30\' W' => array( -55.5, -37.5 ),
459
			'0° 0\' N, 0° 0\' E' => array( 0, 0 ),
460
		);
461
462
		$this->assertIsDirectionalFormatMap( $coordinates, GeoCoordinateFormatter::TYPE_DM );
463
	}
464
465
	/**
466
	 * @param array[] $coordinates
467
	 * @param string $format One of the GeoCoordinateFormatter::TYPE_… constants
468
	 */
469
	private function assertIsDirectionalFormatMap( array $coordinates, $format ) {
470
		foreach ( $coordinates as $expected => $arguments ) {
471
			$options = new FormatterOptions();
472
			$options->setOption( GeoCoordinateFormatter::OPT_FORMAT, $format );
473
			$options->setOption( GeoCoordinateFormatter::OPT_DIRECTIONAL, true );
474
			$options->setOption( GeoCoordinateFormatter::OPT_PRECISION, 1.0/60 );
475
476
			$this->assertFormatsCorrectly(
477
				new LatLongValue( $arguments[0], $arguments[1] ),
478
				$options,
479
				$expected
480
			);
481
		}
482
	}
483
484
	public function testDirectionalOptionGetsAppliedForFloats() {
485
		$coordinates = array(
486
			'55.75 N, 37.25 W' => array( 55.755786, -37.25633 ),
487
			'55.75 S, 37.25 E' => array( -55.755786, 37.25633 ),
488
			'55 S, 37.25 W' => array( -55, -37.25633 ),
489
			'5.5 N, 37 E' => array( 5.5, 37 ),
490
			'0 N, 0 E' => array( 0, 0 ),
491
		);
492
493
		$this->assertIsDirectionalFormatMap( $coordinates, GeoCoordinateFormatter::TYPE_FLOAT );
494
	}
495
496
	private function provideSpacingLevelOptions() {
497
		return array(
498
			'none' => array(),
499
			'latlong' => array( GeoCoordinateFormatter::OPT_SPACE_LATLONG ),
500
			'direction' => array( GeoCoordinateFormatter::OPT_SPACE_DIRECTION ),
501
			'coordparts' => array( GeoCoordinateFormatter::OPT_SPACE_COORDPARTS ),
502
			'latlong_direction' => array(
503
				GeoCoordinateFormatter::OPT_SPACE_LATLONG,
504
				GeoCoordinateFormatter::OPT_SPACE_DIRECTION
505
			),
506
			'all' => array(
507
				GeoCoordinateFormatter::OPT_SPACE_LATLONG,
508
				GeoCoordinateFormatter::OPT_SPACE_DIRECTION,
509
				GeoCoordinateFormatter::OPT_SPACE_COORDPARTS,
510
			),
511
		);
512
	}
513
514
	public function testSpacingOptionGetsAppliedForDecimalMinutes() {
515
		$coordinates = array(
516
			'none' => array(
517
				'55°0\'N,37°0\'E' => array( 55, 37 ),
518
				'55°30\'N,37°30\'W' => array( 55.5, -37.5 ),
519
				'0°0\'N,0°0\'E' => array( 0, 0 ),
520
			),
521
			'latlong' => array(
522
				'55°0\'N, 37°0\'E' => array( 55, 37 ),
523
				'55°30\'N, 37°30\'W' => array( 55.5, -37.5 ),
524
				'0°0\'N, 0°0\'E' => array( 0, 0 ),
525
			),
526
			'direction' => array(
527
				'55°0\' N,37°0\' E' => array( 55, 37 ),
528
				'55°30\' N,37°30\' W' => array( 55.5, -37.5 ),
529
				'0°0\' N,0°0\' E' => array( 0, 0 ),
530
			),
531
			'coordparts' => array(
532
				'55° 0\'N,37° 0\'E' => array( 55, 37 ),
533
				'55° 30\'N,37° 30\'W' => array( 55.5, -37.5 ),
534
				'0° 0\'N,0° 0\'E' => array( 0, 0 ),
535
			),
536
			'latlong_direction' => array(
537
				'55°0\' N, 37°0\' E' => array( 55, 37 ),
538
				'55°30\' N, 37°30\' W' => array( 55.5, -37.5 ),
539
				'0°0\' N, 0°0\' E' => array( 0, 0 ),
540
			),
541
		);
542
543
		$this->assertSpacingCorrect( $coordinates, GeoCoordinateFormatter::TYPE_DM );
544
	}
545
546
	/**
547
	 * @param array[] $coordSets
548
	 * @param string $format One of the GeoCoordinateFormatter::TYPE_… constants
549
	 */
550
	private function assertSpacingCorrect( array $coordSets, $format ) {
551
		$spacingLevelOptions = $this->provideSpacingLevelOptions();
552
		foreach ( $coordSets as $spacingKey => $coordinates ) {
553
			foreach ( $coordinates as $expected => $arguments ) {
554
				$options = new FormatterOptions();
555
				$options->setOption( GeoCoordinateFormatter::OPT_FORMAT, $format );
556
				$options->setOption( GeoCoordinateFormatter::OPT_DIRECTIONAL, true );
557
				$options->setOption( GeoCoordinateFormatter::OPT_PRECISION, 1.0/60 );
558
				$options->setOption( GeoCoordinateFormatter::OPT_SPACING_LEVEL, $spacingLevelOptions[$spacingKey] );
559
560
				$this->assertFormatsCorrectly(
561
					new LatLongValue( $arguments[0], $arguments[1] ),
562
					$options,
563
					$expected
564
				);
565
			}
566
		}
567
	}
568
569
	public function testSpacingOptionGetsAppliedForFloats() {
570
		$coordinates = array(
571
			'none' => array(
572
				'55.75N,37.25W' => array( 55.755786, -37.25633 ),
573
				'0N,0E' => array( 0, 0 ),
574
			),
575
			'latlong' => array(
576
				'55.75N, 37.25W' => array( 55.755786, -37.25633 ),
577
				'0N, 0E' => array( 0, 0 ),
578
			),
579
			'direction' => array(
580
				'55.75 N,37.25 W' => array( 55.755786, -37.25633 ),
581
				'0 N,0 E' => array( 0, 0 ),
582
			),
583
			'coordparts' => array(
584
				'55.75N,37.25W' => array( 55.755786, -37.25633 ),
585
				'0N,0E' => array( 0, 0 ),
586
			),
587
			'latlong_direction' => array(
588
				'55.75 N, 37.25 W' => array( 55.755786, -37.25633 ),
589
				'0 N, 0 E' => array( 0, 0 ),
590
			),
591
			'all' => array(
592
				'55.75 N, 37.25 W' => array( 55.755786, -37.25633 ),
593
				'0 N, 0 E' => array( 0, 0 ),
594
			),
595
		);
596
597
		$this->assertSpacingCorrect( $coordinates, GeoCoordinateFormatter::TYPE_FLOAT );
598
	}
599
600
	public function testWrongType() {
601
		$this->setExpectedException( 'InvalidArgumentException' );
602
603
		$formatter = new GeoCoordinateFormatter( new FormatterOptions() );
604
605
		$formatter->format( new StringValue( 'Evil' ) );
0 ignored issues
show
Documentation introduced by
new \DataValues\StringValue('Evil') is of type object<DataValues\StringValue>, but the function expects a object<DataValues\Geo\Values\LatLongValue>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
606
	}
607
608
	public function testGivenInvalidFormattingOption_formatThrowsException() {
609
		$options = new FormatterOptions();
610
		$options->setOption( GeoCoordinateFormatter::OPT_FORMAT, 'not a format' );
611
		$formatter = new GeoCoordinateFormatter( $options );
612
613
		$this->setExpectedException( 'InvalidArgumentException' );
614
		$formatter->format( new LatLongValue( 0, 0 ) );
615
	}
616
617
	/**
618
	 * @dataProvider invalidPrecisionProvider
619
	 */
620
	public function testFormatWithInvalidPrecision_fallsBackToDefaultPrecision( $precision ) {
621
		$options = new FormatterOptions();
622
		$options->setOption( GeoCoordinateFormatter::OPT_PRECISION, $precision );
623
		$formatter = new GeoCoordinateFormatter( $options );
624
625
		$formatted = $formatter->format( new LatLongValue( 1.2, 3.4 ) );
626
		$this->assertSame( '1.2, 3.4', $formatted );
627
	}
628
629
	/**
630
	 * @dataProvider invalidPrecisionProvider
631
	 */
632
	public function testFormatLatLongValueWithInvalidPrecision_fallsBackToDefaultPrecision( $precision ) {
633
		$formatter = new GeoCoordinateFormatter( new FormatterOptions() );
634
635
		$formatted = $formatter->formatLatLongValue( new LatLongValue( 1.2, 3.4 ), $precision );
636
		$this->assertSame( '1.2, 3.4', $formatted );
637
	}
638
639
	public function invalidPrecisionProvider() {
640
		return array(
641
			array( null ),
642
			array( '' ),
643
			array( 0 ),
644
			array( -1 ),
645
			array( NAN ),
646
			array( INF ),
647
		);
648
	}
649
650
}
651